From 7be72cd99e25a9277ea44fe989b221a819dbbc7f Mon Sep 17 00:00:00 2001 From: "ir.__.si" Date: Wed, 15 Nov 2023 12:31:03 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Feat:=20#17=20-=20KeyboardLayout=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(TextField=20=EB=AA=A8=EC=85=98=20?= =?UTF-8?q?=EB=B6=80=EB=93=9C=EB=9F=BD=EA=B2=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Auth/SignIn/SignInViewController.swift | 38 +++++++++--------- .../MainSignUp/MainSignUpView.swift | 21 +++++++++- .../Auth/SignUp/SignUpViewController.swift | 40 +++++++++---------- 3 files changed, 60 insertions(+), 39 deletions(-) diff --git a/CMC/Sources/Presenter/Auth/SignIn/SignInViewController.swift b/CMC/Sources/Presenter/Auth/SignIn/SignInViewController.swift index c576016..30f2487 100644 --- a/CMC/Sources/Presenter/Auth/SignIn/SignInViewController.swift +++ b/CMC/Sources/Presenter/Auth/SignIn/SignInViewController.swift @@ -199,7 +199,7 @@ final class SignInViewController: BaseViewController { } signInButton.snp.makeConstraints { make in - make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom).offset(-20) + make.bottom.equalTo(view.keyboardLayoutGuide.snp.top).offset(-20) make.leading.equalToSuperview().offset(24) make.trailing.equalToSuperview().offset(-24) make.height.equalTo(56) @@ -208,19 +208,29 @@ final class SignInViewController: BaseViewController { override func bind() { - NotificationManager.shared.keyboardHeightSubject +// NotificationManager.shared.keyboardHeightSubject +// .withUnretained(self) +// .subscribe(onNext: { owner, keyboardHeight in +// let realHeight = keyboardHeight > 0 ? keyboardHeight - 30 : 0 +// owner.signInButton.snp.updateConstraints { make in +// make.bottom.equalTo(owner.view.safeAreaLayoutGuide.snp.bottom).offset(-20 - realHeight) +// } +// UIView.animate(withDuration: 0.3) { +// owner.view.layoutIfNeeded() +// } +// }) +// .disposed(by: disposeBag) + + self.view.rx.tapGesture() + .debug() + .when(.recognized) .withUnretained(self) - .subscribe(onNext: { owner, keyboardHeight in - let realHeight = keyboardHeight > 0 ? keyboardHeight - 30 : 0 - owner.signInButton.snp.updateConstraints { make in - make.bottom.equalTo(owner.view.safeAreaLayoutGuide.snp.bottom).offset(-20 - realHeight) - } - UIView.animate(withDuration: 0.3) { - owner.view.layoutIfNeeded() - } + .subscribe(onNext: { owner, _ in + owner.view.endEditing(true) }) .disposed(by: disposeBag) + passwordTextField.accessoryState .observe(on: MainScheduler.instance) .withUnretained(self) @@ -253,11 +263,3 @@ final class SignInViewController: BaseViewController { } } - - -// MARK: - Extension -extension SignInViewController { - override func touchesBegan(_ touches: Set, with event: UIEvent?) { - self.view.endEditing(true) - } -} diff --git a/CMC/Sources/Presenter/Auth/SignUp/ScrollPages/MainSignUp/MainSignUpView.swift b/CMC/Sources/Presenter/Auth/SignUp/ScrollPages/MainSignUp/MainSignUpView.swift index 80c1923..be8d554 100644 --- a/CMC/Sources/Presenter/Auth/SignUp/ScrollPages/MainSignUp/MainSignUpView.swift +++ b/CMC/Sources/Presenter/Auth/SignUp/ScrollPages/MainSignUp/MainSignUpView.swift @@ -152,7 +152,6 @@ final class MainSignUpView: BaseView { mainContentView.snp.makeConstraints { make in make.edges.equalTo(scrollView.contentLayoutGuide) make.width.equalTo(scrollView.frameLayoutGuide.snp.width) -// make.height.greaterThanOrEqualTo(500) } emailTextField.snp.makeConstraints{ make in @@ -242,6 +241,16 @@ final class MainSignUpView: BaseView { }) .disposed(by: disposeBag) + self.rx.tapGesture() + .when(.recognized) + .withUnretained(self) + .subscribe(onNext: { owner, gesture in + let location = gesture.location(in: owner.scrollView) + if !owner.isPointInsideTextField(location) { + owner.endEditing(true) + } + }) + .disposed(by: disposeBag) let input = MainSignUpViewModel.Input( email: emailTextField.rx.text.orEmpty.asObservable(), @@ -302,3 +311,13 @@ final class MainSignUpView: BaseView { } } + + +// MARK: - Extension +extension MainSignUpView { + fileprivate func isPointInsideTextField(_ point: CGPoint) -> Bool { + // 모든 텍스트 필드를 순회하면서 탭된 위치가 텍스트 필드 내부인지 확인합니다. + let textFields = [emailTextField, passwordTextField, confirmPasswordTextField, nameTextField] + return textFields.contains(where: { $0.frame.contains(point) }) + } +} diff --git a/CMC/Sources/Presenter/Auth/SignUp/SignUpViewController.swift b/CMC/Sources/Presenter/Auth/SignUp/SignUpViewController.swift index d4c4478..20d75a8 100644 --- a/CMC/Sources/Presenter/Auth/SignUp/SignUpViewController.swift +++ b/CMC/Sources/Presenter/Auth/SignUp/SignUpViewController.swift @@ -113,7 +113,7 @@ class SignUpViewController: BaseViewController { nextButton.snp.makeConstraints{ nextButton in nextButton.leading.trailing.equalToSuperview().inset(20) - nextButton.bottom.equalTo(self.view.safeAreaLayoutGuide).offset(-20) + nextButton.bottom.equalTo(self.view.keyboardLayoutGuide.snp.top).offset(-20) nextButton.height.equalTo(56) } @@ -127,18 +127,18 @@ class SignUpViewController: BaseViewController { override func bind() { - NotificationManager.shared.keyboardHeightSubject - .withUnretained(self) - .subscribe(onNext: { owner, keyboardHeight in - let realHeight = keyboardHeight > 0 ? keyboardHeight : 20 - owner.nextButton.snp.updateConstraints { make in - make.bottom.equalTo(self.view.safeAreaLayoutGuide).offset(-realHeight) - } - UIView.animate(withDuration: 0.3) { - owner.view.layoutIfNeeded() - } - }) - .disposed(by: disposeBag) +// NotificationManager.shared.keyboardHeightSubject +// .withUnretained(self) +// .subscribe(onNext: { owner, keyboardHeight in +// let realHeight = keyboardHeight > 0 ? keyboardHeight : 20 +// owner.nextButton.snp.updateConstraints { make in +// make.bottom.equalTo(self.view.safeAreaLayoutGuide).offset(-realHeight) +// } +// UIView.animate(withDuration: 0.3) { +// owner.view.layoutIfNeeded() +// } +// }) +// .disposed(by: disposeBag) nextButton.rx.tap .withLatestFrom(cmcPager.getCurrentPage()) @@ -151,13 +151,13 @@ class SignUpViewController: BaseViewController { }) .disposed(by: disposeBag) - self.view.rx.tapGesture() - .when(.recognized) - .withUnretained(self) - .subscribe(onNext: { owner, _ in - owner.view.endEditing(true) - }) - .disposed(by: disposeBag) +// self.view.rx.tapGesture() +// .when(.recognized) +// .withUnretained(self) +// .subscribe(onNext: { owner, _ in +// owner.view.endEditing(true) +// }) +// .disposed(by: disposeBag) let input = SignUpViewModel.Input( backButtonTapped: navigationBar.backButton.rx.tapped().asObservable(),