diff --git a/KkuMulKum/Application/SceneDelegate.swift b/KkuMulKum/Application/SceneDelegate.swift index 481d791c..9ba7957d 100644 --- a/KkuMulKum/Application/SceneDelegate.swift +++ b/KkuMulKum/Application/SceneDelegate.swift @@ -61,7 +61,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { let mainTabBarController = MainTabBarController() let navigationController = UINavigationController( rootViewController: mainTabBarController, - isBorderNeeded: true + isBorderNeeded: false ) navigationController.isNavigationBarHidden = true diff --git a/KkuMulKum/Resource/Base/BaseViewController.swift b/KkuMulKum/Resource/Base/BaseViewController.swift index 6938a9c5..570a75db 100644 --- a/KkuMulKum/Resource/Base/BaseViewController.swift +++ b/KkuMulKum/Resource/Base/BaseViewController.swift @@ -44,12 +44,9 @@ extension BaseViewController { .font: UIFont.pretendard(.body03) ] - isBorderHidden ? navigationController?.hideBorder() : navigationController?.showBorder() - - let barAppearance = UINavigationBarAppearance() - barAppearance.backgroundColor = .white - navigationItem.standardAppearance = barAppearance - navigationItem.scrollEdgeAppearance = barAppearance + if !isBorderHidden { + addBorder() + } } /// 네비게이션 바 BackButton 구성 @@ -67,15 +64,44 @@ extension BaseViewController { } } + +// MARK: - UIGestureRecognizerDelegate + extension BaseViewController: UIGestureRecognizerDelegate { func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { return navigationController?.viewControllers.count ?? 0 > 1 } } + +// MARK: - Private Method + private extension BaseViewController { @objc func backButtonDidTap() { navigationController?.popViewController(animated: true) } + + func addBorder() { + let identifier = "border" + guard view.subviews.first(where: { $0.accessibilityIdentifier == identifier }) == nil else { return } + + let safeArea = view.safeAreaLayoutGuide + let border = UIView(backgroundColor: .gray2).then { + $0.accessibilityIdentifier = identifier + } + + view.addSubview(border) + + border.snp.makeConstraints { + $0.top.equalTo(safeArea) + $0.horizontalEdges.equalToSuperview() + $0.height.equalTo(1) + } + + view.bringSubviewToFront(border) + + view.setNeedsLayout() + view.layoutIfNeeded() + } } diff --git a/KkuMulKum/Resource/Extension/UINavigationController+.swift b/KkuMulKum/Resource/Extension/UINavigationController+.swift index 0e6fd630..bcb61851 100644 --- a/KkuMulKum/Resource/Extension/UINavigationController+.swift +++ b/KkuMulKum/Resource/Extension/UINavigationController+.swift @@ -11,45 +11,11 @@ extension UINavigationController { convenience init(rootViewController: UIViewController, isBorderNeeded: Bool) { self.init(rootViewController: rootViewController) - if isBorderNeeded { - addBorder() - } - } - - func showBorder() { - let border = findBottomBorder() - border?.isHidden = false - } - - func hideBorder() { - let border = findBottomBorder() - border?.isHidden = true - } -} - -private extension UINavigationController { - enum Constants { - static let bottomBorderName = "BottomBorder" - static let bottomBorderWidth: CGFloat = Screen.height(1) - } - - func addBorder() { - guard findBottomBorder() == nil else { return } + let barAppearance = UINavigationBarAppearance() + barAppearance.backgroundColor = .white + barAppearance.shadowColor = isBorderNeeded ? .gray2 : nil - let border = CALayer() - border.name = Constants.bottomBorderName - border.backgroundColor = UIColor.gray2.cgColor - border.frame = CGRect( - x: 0, - y: navigationBar.frame.height - Constants.bottomBorderWidth, - width: navigationBar.frame.width, - height: Constants.bottomBorderWidth - ) - - navigationBar.layer.addSublayer(border) - } - - func findBottomBorder() -> CALayer? { - return navigationBar.layer.sublayers?.first(where: { $0.name == Constants.bottomBorderName }) + navigationBar.standardAppearance = barAppearance + navigationBar.scrollEdgeAppearance = barAppearance } } diff --git a/KkuMulKum/Source/AddPromise/ViewController/AddPromiseCompleteViewController.swift b/KkuMulKum/Source/AddPromise/ViewController/AddPromiseCompleteViewController.swift index 93233626..1dc39cec 100644 --- a/KkuMulKum/Source/AddPromise/ViewController/AddPromiseCompleteViewController.swift +++ b/KkuMulKum/Source/AddPromise/ViewController/AddPromiseCompleteViewController.swift @@ -38,7 +38,7 @@ final class AddPromiseCompleteViewController: BaseViewController { override func viewDidLoad() { super.viewDidLoad() - setupNavigationBarTitle(with: "내 모임 추가하기") + setupNavigationBarTitle(with: "내 모임 추가하기", isBorderHidden: true) navigationItem.hidesBackButton = true } @@ -63,7 +63,6 @@ final class AddPromiseCompleteViewController: BaseViewController { animated: false ) rootViewController.navigationController?.pushViewController( - PromiseViewController( viewModel: PromiseViewModel( promiseID: owner.promiseID, diff --git a/KkuMulKum/Source/AddPromise/ViewController/AddPromiseViewController.swift b/KkuMulKum/Source/AddPromise/ViewController/AddPromiseViewController.swift index b5b60852..75e60e8e 100644 --- a/KkuMulKum/Source/AddPromise/ViewController/AddPromiseViewController.swift +++ b/KkuMulKum/Source/AddPromise/ViewController/AddPromiseViewController.swift @@ -42,7 +42,7 @@ final class AddPromiseViewController: BaseViewController { override func viewDidLoad() { super.viewDidLoad() - setupNavigationBarTitle(with: "약속 추가하기") + setupNavigationBarTitle(with: "약속 추가하기", isBorderHidden: true) setupNavigationBarBackButton() bindViewModel() diff --git a/KkuMulKum/Source/AddPromise/ViewController/SelectMemberViewController.swift b/KkuMulKum/Source/AddPromise/ViewController/SelectMemberViewController.swift index 51be394c..3131e8be 100644 --- a/KkuMulKum/Source/AddPromise/ViewController/SelectMemberViewController.swift +++ b/KkuMulKum/Source/AddPromise/ViewController/SelectMemberViewController.swift @@ -41,7 +41,7 @@ final class SelectMemberViewController: BaseViewController { override func viewDidLoad() { super.viewDidLoad() - setupNavigationBarTitle(with: "약속 추가하기") + setupNavigationBarTitle(with: "약속 추가하기", isBorderHidden: true) setupNavigationBarBackButton() bindViewModel() diff --git a/KkuMulKum/Source/AddPromise/ViewController/SelectPenaltyViewController.swift b/KkuMulKum/Source/AddPromise/ViewController/SelectPenaltyViewController.swift index 85923118..c58ddcdc 100644 --- a/KkuMulKum/Source/AddPromise/ViewController/SelectPenaltyViewController.swift +++ b/KkuMulKum/Source/AddPromise/ViewController/SelectPenaltyViewController.swift @@ -40,7 +40,7 @@ final class SelectPenaltyViewController: BaseViewController { override func viewDidLoad() { super.viewDidLoad() - setupNavigationBarTitle(with: "약속 추가하기") + setupNavigationBarTitle(with: "약속 추가하기", isBorderHidden: true) setupNavigationBarBackButton() bindViewModel() diff --git a/KkuMulKum/Source/MeetingInfo/ViewController/MeetingInfoViewController.swift b/KkuMulKum/Source/MeetingInfo/ViewController/MeetingInfoViewController.swift index 32078ba2..66836109 100644 --- a/KkuMulKum/Source/MeetingInfo/ViewController/MeetingInfoViewController.swift +++ b/KkuMulKum/Source/MeetingInfo/ViewController/MeetingInfoViewController.swift @@ -96,7 +96,7 @@ private extension MeetingInfoViewController { output.info .drive(with: self) { owner, meetingInfo in guard let info = meetingInfo else { return } - owner.title = info.name + owner.setupNavigationBarTitle(with: info.name) owner.rootView.configureInfo( createdAt: info.createdAt, metCount: info.metCount diff --git a/KkuMulKum/Source/Onboarding/Login/ViewController/LoginViewController.swift b/KkuMulKum/Source/Onboarding/Login/ViewController/LoginViewController.swift index 360dbb3d..60ea86d9 100644 --- a/KkuMulKum/Source/Onboarding/Login/ViewController/LoginViewController.swift +++ b/KkuMulKum/Source/Onboarding/Login/ViewController/LoginViewController.swift @@ -84,7 +84,7 @@ class LoginViewController: BaseViewController { let mainTabBarController = MainTabBarController() let navigationController = UINavigationController( rootViewController: mainTabBarController, - isBorderNeeded: true + isBorderNeeded: false ) navigationController.isNavigationBarHidden = true navigationController.modalPresentationStyle = .fullScreen @@ -102,7 +102,7 @@ class LoginViewController: BaseViewController { } else { let navigationController = UINavigationController( rootViewController: nicknameViewController, - isBorderNeeded: true + isBorderNeeded: false ) navigationController.modalPresentationStyle = .fullScreen navigationController.modalTransitionStyle = .crossDissolve diff --git a/KkuMulKum/Source/Onboarding/Welcome/ViewController/WelcomeViewController.swift b/KkuMulKum/Source/Onboarding/Welcome/ViewController/WelcomeViewController.swift index 6bf1ed48..b06d0c66 100644 --- a/KkuMulKum/Source/Onboarding/Welcome/ViewController/WelcomeViewController.swift +++ b/KkuMulKum/Source/Onboarding/Welcome/ViewController/WelcomeViewController.swift @@ -54,7 +54,7 @@ class WelcomeViewController: BaseViewController { let navigationController = UINavigationController( rootViewController: mainTabBarController, - isBorderNeeded: true + isBorderNeeded: false ) navigationController.isNavigationBarHidden = true diff --git a/KkuMulKum/Source/Promise/PagePromise/ViewController/PromiseViewController.swift b/KkuMulKum/Source/Promise/PagePromise/ViewController/PromiseViewController.swift index e57b4147..66761ff5 100644 --- a/KkuMulKum/Source/Promise/PagePromise/ViewController/PromiseViewController.swift +++ b/KkuMulKum/Source/Promise/PagePromise/ViewController/PromiseViewController.swift @@ -149,7 +149,7 @@ class PromiseViewController: BaseViewController { private extension PromiseViewController { func setupBindings() { viewModel.promiseInfo.bindOnMain(with: self) { owner, info in - owner.setupNavigationBarTitle(with: info?.promiseName ?? "", isBorderHidden: false) + owner.setupNavigationBarTitle(with: info?.promiseName ?? "", isBorderHidden: true) owner.promiseInfoViewController.rootView.editButton.isHidden = !(info?.isParticipant ?? false) owner.setupPromiseEditButton(isHidden: !(info?.isParticipant ?? false))