From 642e4528ef652b9ecef30c9255aaa8aeca88c4db Mon Sep 17 00:00:00 2001 From: LeeMyeongJin Date: Fri, 24 Nov 2023 16:54:34 +0900 Subject: [PATCH 01/10] =?UTF-8?q?[Fix]=20#216=20-=20=EB=B0=94=ED=85=80=20?= =?UTF-8?q?=EC=8B=9C=ED=8A=B8=20keyboardWillShow=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존 일반 상수에서, 시스템을 활용한 코드로 대체 했습니다. --- .../Global/UIComponents/CustomBottomSheetVC.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift index b0e461ac..45a3eb2d 100644 --- a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift +++ b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift @@ -290,7 +290,12 @@ extension CustomBottomSheetVC { // MARK: - @objc Function extension CustomBottomSheetVC { @objc private func keyboardWillShow(_ sender: Notification) { - self.view.frame.origin.y = -291 + if let keyboardFrame: NSValue = sender.userInfo? [UIResponder.keyboardFrameEndUserInfoKey] as? NSValue { + let keybaordRectangle = keyboardFrame.cgRectValue + let keyboardHeight = keybaordRectangle.height + + self.view.frame.origin.y -= (keyboardHeight - view.safeAreaInsets.bottom) + } } @objc private func keyboardWillHide(_ sender: Notification) { From fc4f8baeeb474135ee553b62b017e1365b697dbc Mon Sep 17 00:00:00 2001 From: LeeMyeongJin Date: Sat, 25 Nov 2023 21:30:30 +0900 Subject: [PATCH 02/10] =?UTF-8?q?[Chore]=20#216=20-=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=EC=97=86=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UIComponents/CustomBottomSheetVC.swift | 63 ++++--------------- 1 file changed, 11 insertions(+), 52 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift index 45a3eb2d..33ffadb1 100644 --- a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift +++ b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift @@ -80,12 +80,11 @@ final class CustomBottomSheetVC: UIViewController { self.setUI() self.setLayout(bottomSheetType) self.setDelegate() - self.setTapGesture() - self.setAddTarget() self.setBinding() if bottomSheetType == .textField { showBottomSheet() setupGestureRecognizer() + self.setAddTarget() } } @@ -112,21 +111,6 @@ final class CustomBottomSheetVC: UIViewController { bottomSheetTextField.delegate = self } - private func dismissBottomSheet() { - UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: { - self.view.layoutIfNeeded() - }, completion: nil) - } - - private func setTapGesture() { - let tap = UITapGestureRecognizer(target: view, action: #selector(UIView.endEditing)) - tap.cancelsTouchesInView = false - view.addGestureRecognizer(tap) - - let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleBackgroundTap)) - backgroundView.addGestureRecognizer(tapGesture) - } - private func setAddTarget() { NotificationCenter.default.addObserver( self, @@ -249,41 +233,17 @@ extension CustomBottomSheetVC { } UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseIn, animations: { - self.backgroundView.alpha = 0.65 self.view.layoutIfNeeded() }, completion: nil) } - private func hideBottomSheetAndGoBack() { - let safeAreaHeight = view.safeAreaLayoutGuide.layoutFrame.height - let bottomPadding = view.safeAreaInsets.bottom - - let topConst = (safeAreaHeight + bottomPadding) - - bottomSheetView.snp.remakeConstraints { make in - make.leading.bottom.trailing.equalToSuperview() - make.top.equalTo(view.snp.top).offset(topConst) - make.height.equalTo(bottomHeight) - } - - UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseIn, animations: { - self.backgroundView.alpha = 0.0 - self.view.layoutIfNeeded() - }) { _ in - if self.presentingViewController != nil { - self.dismiss(animated: false, completion: nil) - } - } - } - private func setupGestureRecognizer() { let dimmedTap = UITapGestureRecognizer(target: self, action: #selector(dimmedViewTapped(_:))) backgroundView.addGestureRecognizer(dimmedTap) backgroundView.isUserInteractionEnabled = true - let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(panGesture)) - swipeGesture.direction = .down - view.addGestureRecognizer(swipeGesture) + let panGesture = UIPanGestureRecognizer(target: self, action: #selector(panGesture(_:))) + view.addGestureRecognizer(panGesture) } } @@ -325,17 +285,16 @@ extension CustomBottomSheetVC { } @objc private func dimmedViewTapped(_ tapRecognizer: UITapGestureRecognizer) { - hideBottomSheetAndGoBack() + let safeAreaHeight = view.safeAreaLayoutGuide.layoutFrame.height } - @objc func panGesture(_ recognizer: UISwipeGestureRecognizer) { - if recognizer.state == .ended { - switch recognizer.direction { - case .down: - hideBottomSheetAndGoBack() - default: - break - } + // 클래스 내에 저장할 변수 추가 + + @objc func panGesture(_ recognizer: UIPanGestureRecognizer) { + + let translation = recognizer.translation(in: bottomSheetView) + default: + break } } } From 24b650f6ac3b421a9dc9f28ebf3146e6fe19415f Mon Sep 17 00:00:00 2001 From: LeeMyeongJin Date: Sat, 25 Nov 2023 21:31:33 +0900 Subject: [PATCH 03/10] =?UTF-8?q?[Feat]=20#216=20-=20=EB=B0=94=ED=85=80=20?= =?UTF-8?q?=EC=8B=9C=ED=8A=B8=20PanGesture=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UIPanGestureRecognizer 를 추가하므로써, 유연하게 작동하는 바텀시트가 되었습니다. --- .../UIComponents/CustomBottomSheetVC.swift | 64 +++++++++++++++---- 1 file changed, 51 insertions(+), 13 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift index 33ffadb1..b800119c 100644 --- a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift +++ b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift @@ -18,7 +18,7 @@ enum SheetType { final class CustomBottomSheetVC: UIViewController { // MARK: - Properties private let backgroundView = UIView().then { - $0.backgroundColor = .black.withAlphaComponent(0.65) + $0.backgroundColor = .g1.withAlphaComponent(0.65) } private let titleNameMaxLength = 20 private var bottomSheetType: SheetType! @@ -251,10 +251,10 @@ extension CustomBottomSheetVC { extension CustomBottomSheetVC { @objc private func keyboardWillShow(_ sender: Notification) { if let keyboardFrame: NSValue = sender.userInfo? [UIResponder.keyboardFrameEndUserInfoKey] as? NSValue { - let keybaordRectangle = keyboardFrame.cgRectValue - let keyboardHeight = keybaordRectangle.height - - self.view.frame.origin.y -= (keyboardHeight - view.safeAreaInsets.bottom) + let keybaordRectangle = keyboardFrame.cgRectValue + let keyboardHeight = keybaordRectangle.height + + self.view.frame.origin.y -= (keyboardHeight - view.safeAreaInsets.bottom) } } @@ -262,14 +262,6 @@ extension CustomBottomSheetVC { self.view.frame.origin.y = 0 } - @objc private func endEditing() { - bottomSheetTextField.resignFirstResponder() - } - - @objc private func handleBackgroundTap() { - dismissBottomSheet() - } - @objc private func textFieldTextDidChange() { guard let text = bottomSheetTextField.text else { return } @@ -286,6 +278,24 @@ extension CustomBottomSheetVC { @objc private func dimmedViewTapped(_ tapRecognizer: UITapGestureRecognizer) { let safeAreaHeight = view.safeAreaLayoutGuide.layoutFrame.height + let bottomPadding = view.safeAreaInsets.bottom + + let topConst = (safeAreaHeight + bottomPadding) + + bottomSheetView.snp.remakeConstraints { make in + make.leading.bottom.trailing.equalToSuperview() + make.top.equalTo(view.snp.top).offset(topConst) + make.height.equalTo(bottomHeight) + } + + UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseIn, animations: { + self.view.layoutIfNeeded() + }, completion: { _ in + if self.presentingViewController != nil { + self.dismiss(animated: false, completion: nil) + } + }) // 하나 이상의 클로저 인수를 전달할때, 후행 클로저 구문을 사용하면 안된다는 경고로 (_) 로 수정 + } // 클래스 내에 저장할 변수 추가 @@ -293,6 +303,34 @@ extension CustomBottomSheetVC { @objc func panGesture(_ recognizer: UIPanGestureRecognizer) { let translation = recognizer.translation(in: bottomSheetView) + let velocity = recognizer.velocity(in: bottomSheetView) + + switch recognizer.state { + case .began: + // 제스처 시작 지점의 좌표를 기록 + let startPoint = recognizer.location(in: bottomSheetView) + print("startPoint = \(startPoint.y)") + case .changed: + // 상하로 스와이프 할 때 위로 스와이프가 안되게 해주기 위해서 조건 설정 + if velocity.y > 0 { + backgroundView.alpha = 0 + UIView.animate(withDuration: 0.25, animations: { + self.view.transform = CGAffineTransform(translationX: 0, y: translation.y) + }) + } + case .ended: + print("translation.y = \(translation.y)") + // 해당 뷰의 y값이 80보다 작으면(작게 이동 시) 뷰의 위치를 다시 원상복구하겠다. = 즉, 다시 y=0인 지점으로 리셋 + if translation.y < 75 { + UIView.animate(withDuration: 0.25, animations: { + self.view.transform = .identity + }) + backgroundView.alpha = 0.65 + // 뷰의 값이 75 이상이면 해당 화면 dismiss (MIU 내규에 따름) + } else { + self.backgroundView.alpha = 0 + dismiss(animated: true, completion: nil) + } default: break } From 6efaaf41ab0dfdf9e57c56d363eb2d74a43eb303 Mon Sep 17 00:00:00 2001 From: LeeMyeongJin Date: Sat, 25 Nov 2023 22:25:06 +0900 Subject: [PATCH 04/10] =?UTF-8?q?[Chore]=20#216=20-=20=EB=B0=B1=EA=B7=B8?= =?UTF-8?q?=EB=9D=BC=EC=9A=B4=EB=93=9C=20=EC=83=89=20=EC=9E=84=EC=8B=9C=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift | 2 +- .../Presentation/CourseDrawing/VC/CourseDrawingVC.swift | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift index b800119c..922062e4 100644 --- a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift +++ b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift @@ -18,7 +18,7 @@ enum SheetType { final class CustomBottomSheetVC: UIViewController { // MARK: - Properties private let backgroundView = UIView().then { - $0.backgroundColor = .g1.withAlphaComponent(0.65) + $0.backgroundColor = .clear } private let titleNameMaxLength = 20 private var bottomSheetType: SheetType! diff --git a/Runnect-iOS/Runnect-iOS/Presentation/CourseDrawing/VC/CourseDrawingVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/CourseDrawing/VC/CourseDrawingVC.swift index 98166a01..b60ecebd 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/CourseDrawing/VC/CourseDrawingVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/CourseDrawing/VC/CourseDrawingVC.swift @@ -261,7 +261,8 @@ extension CourseDrawingVC { self.mapView.capturePathImage() self.dismiss(animated: true) } - self.present(bottomSheetVC, animated: false) + self.present(bottomSheetVC, animated: true) + // 일단 true로 설정 (background 색 관련하여 여기서 설정할지, 바텀시트에서 설정할지 생각) } } From ff391f402e8aa914d62c439d2e38c1f988431b6e Mon Sep 17 00:00:00 2001 From: LeeMyeongJin Date: Sat, 25 Nov 2023 22:25:24 +0900 Subject: [PATCH 05/10] =?UTF-8?q?[Chore]=20#216=20-=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=EC=BD=94=EB=93=9C,=20=EC=A3=BC=EC=84=9D?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runnect-iOS/Global/Base/BaseView.swift | 1 - .../UIComponents/CustomBottomSheetVC.swift | 29 +++++++------------ .../CourseDrawing/VC/CourseDrawingVC.swift | 9 +++--- 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Global/Base/BaseView.swift b/Runnect-iOS/Runnect-iOS/Global/Base/BaseView.swift index e151b1d5..b6616b5c 100644 --- a/Runnect-iOS/Runnect-iOS/Global/Base/BaseView.swift +++ b/Runnect-iOS/Runnect-iOS/Global/Base/BaseView.swift @@ -38,4 +38,3 @@ class BaseView: UIView, BaseViewProtocol { func setLayout() { } } - diff --git a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift index 922062e4..f8a5146d 100644 --- a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift +++ b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift @@ -231,12 +231,12 @@ extension CustomBottomSheetVC { make.top.equalTo(view.snp.top).offset(topConst) make.height.equalTo(bottomHeight) } - + UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseIn, animations: { self.view.layoutIfNeeded() }, completion: nil) } - + private func setupGestureRecognizer() { let dimmedTap = UITapGestureRecognizer(target: self, action: #selector(dimmedViewTapped(_:))) backgroundView.addGestureRecognizer(dimmedTap) @@ -289,45 +289,36 @@ extension CustomBottomSheetVC { } UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseIn, animations: { - self.view.layoutIfNeeded() - }, completion: { _ in - if self.presentingViewController != nil { + self.view.layoutIfNeeded() + }, completion: { _ in + if self.presentingViewController != nil { self.dismiss(animated: false, completion: nil) - } - }) // 하나 이상의 클로저 인수를 전달할때, 후행 클로저 구문을 사용하면 안된다는 경고로 (_) 로 수정 + } + }) // 하나 이상의 클로저 인수를 전달할때, 후행 클로저 구문을 사용하면 안된다는 경고로 (_) 로 수정 } - // 클래스 내에 저장할 변수 추가 - @objc func panGesture(_ recognizer: UIPanGestureRecognizer) { let translation = recognizer.translation(in: bottomSheetView) let velocity = recognizer.velocity(in: bottomSheetView) switch recognizer.state { - case .began: - // 제스처 시작 지점의 좌표를 기록 - let startPoint = recognizer.location(in: bottomSheetView) - print("startPoint = \(startPoint.y)") case .changed: - // 상하로 스와이프 할 때 위로 스와이프가 안되게 해주기 위해서 조건 설정 - if velocity.y > 0 { + if velocity.y > 0 { // 아래로만 Pan 가능한 로직 backgroundView.alpha = 0 UIView.animate(withDuration: 0.25, animations: { self.view.transform = CGAffineTransform(translationX: 0, y: translation.y) }) } case .ended: - print("translation.y = \(translation.y)") - // 해당 뷰의 y값이 80보다 작으면(작게 이동 시) 뷰의 위치를 다시 원상복구하겠다. = 즉, 다시 y=0인 지점으로 리셋 + // translation.y 값이 75보다 작으면(작게 이동 시) 뷰의 위치를 다시 원상복구하겠다. = 즉, 다시 y=0인 지점으로 리셋 if translation.y < 75 { UIView.animate(withDuration: 0.25, animations: { self.view.transform = .identity }) backgroundView.alpha = 0.65 - // 뷰의 값이 75 이상이면 해당 화면 dismiss (MIU 내규에 따름) - } else { + } else { // translation.y 75 이상이면 해당 화면 dismiss 직접 사용해보니 적절한 값이 75라고 판단 self.backgroundView.alpha = 0 dismiss(animated: true, completion: nil) } diff --git a/Runnect-iOS/Runnect-iOS/Presentation/CourseDrawing/VC/CourseDrawingVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/CourseDrawing/VC/CourseDrawingVC.swift index b60ecebd..c3fe8acf 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/CourseDrawing/VC/CourseDrawingVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/CourseDrawing/VC/CourseDrawingVC.swift @@ -343,7 +343,7 @@ extension CourseDrawingVC { if SelectedInfo.shared.type == .map { self.aboutMapNoticeView.addSubview(aboutMapNoticeLabel) - self.naviBarContainerStackView.addArrangedSubviews(underlineView,aboutMapNoticeView) + self.naviBarContainerStackView.addArrangedSubviews(underlineView, aboutMapNoticeView) underlineView.snp.makeConstraints { $0.leading.trailing.equalToSuperview() @@ -393,7 +393,7 @@ extension CourseDrawingVC { make.trailing.equalTo(view.safeAreaLayoutGuide) make.top.equalTo(view.snp.bottom) } - + completeButton.snp.makeConstraints { make in make.leading.trailing.equalTo(view.safeAreaLayoutGuide).inset(16) make.height.equalTo(44) @@ -433,11 +433,11 @@ extension CourseDrawingVC { guard let departureLocationModel = self.departureLocationModel else { return nil } let path = mapView.getMarkersLatLng().map { $0.toRNLocationModel() } let courseDrawingRequestData = CourseDrawingRequestData(path: path, -// title : self.courseName, + // title : self.courseName, distance: self.distance, departureAddress: departureLocationModel.departureAddress, departureName: departureLocationModel.departureName) - + let courseDrawingRequestDto = CourseDrawingRequestDto(image: imageData, data: courseDrawingRequestData) return courseDrawingRequestDto @@ -498,4 +498,3 @@ extension CourseDrawingVC { } } } - From cc29518c700969b1238329d7a72972aa08da0646 Mon Sep 17 00:00:00 2001 From: LeeMyeongJin Date: Mon, 27 Nov 2023 16:55:40 +0900 Subject: [PATCH 06/10] =?UTF-8?q?[Fix]=20#216=20-=20=ED=95=84=EC=9A=94=20?= =?UTF-8?q?=EC=97=86=EB=8A=94=20=EB=A0=88=EC=9D=B4=EC=95=84=EC=9B=83=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift index f8a5146d..5bd1b722 100644 --- a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift +++ b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift @@ -183,7 +183,6 @@ extension CustomBottomSheetVC { bottomSheetView.snp.makeConstraints { make in make.leading.bottom.trailing.equalToSuperview() make.top.equalTo(view.snp.top).offset(topConst) - make.height.equalTo(bottomHeight) } dismissIndicatorView.snp.makeConstraints { make in @@ -199,7 +198,6 @@ extension CustomBottomSheetVC { } bottomSheetTextField.snp.makeConstraints { make in - make.centerX.equalToSuperview() make.top.equalTo(contentsLabel.snp.bottom).offset(19) make.leading.trailing.equalToSuperview().inset(16) make.height.equalTo(44) @@ -229,7 +227,6 @@ extension CustomBottomSheetVC { bottomSheetView.snp.remakeConstraints { make in make.leading.bottom.trailing.equalToSuperview() make.top.equalTo(view.snp.top).offset(topConst) - make.height.equalTo(bottomHeight) } UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseIn, animations: { @@ -285,7 +282,6 @@ extension CustomBottomSheetVC { bottomSheetView.snp.remakeConstraints { make in make.leading.bottom.trailing.equalToSuperview() make.top.equalTo(view.snp.top).offset(topConst) - make.height.equalTo(bottomHeight) } UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseIn, animations: { From ccd9041ebbeb67111039b549b6d8f6d1619ffbdd Mon Sep 17 00:00:00 2001 From: LeeMyeongJin Date: Mon, 27 Nov 2023 16:58:55 +0900 Subject: [PATCH 07/10] =?UTF-8?q?[Feat]=20#216=20-=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 약간의 코드 수정이 있었습니다. 코드 선언위치, 키보드 위치 관련 코드, 뷰 배경 흐려짐 관련 코드를 수정 하였습니다. --- .../UIComponents/CustomBottomSheetVC.swift | 58 +++++++++++-------- .../CourseDrawing/VC/CourseDrawingVC.swift | 5 +- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift index 5bd1b722..7eddd932 100644 --- a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift +++ b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift @@ -17,19 +17,19 @@ enum SheetType { final class CustomBottomSheetVC: UIViewController { // MARK: - Properties - private let backgroundView = UIView().then { - $0.backgroundColor = .clear - } - private let titleNameMaxLength = 20 - private var bottomSheetType: SheetType! + var backgroundTapAction: (() -> Void)? var completeButtonTapAction: ((String) -> Void)? - // 바텀 시트 높이 - let bottomHeight: CGFloat = 206 + private let titleNameMaxLength = 20 + private let bottomHeight: CGFloat = 206 + private let backgroundView = UIView().then { $0.backgroundColor = .g1.withAlphaComponent(0.65) } + private var cancelBag = CancelBag() + private var bottomSheetType: SheetType! // MARK: - UI Components + private let bottomSheetView = UIView().then { $0.backgroundColor = .w1 $0.layer.cornerRadius = 20 @@ -65,6 +65,7 @@ final class CustomBottomSheetVC: UIViewController { } // MARK: - Initialization + init(type: SheetType) { super.init(nibName: nil, bundle: nil) self.bottomSheetType = type @@ -75,20 +76,22 @@ final class CustomBottomSheetVC: UIViewController { } // MARK: - View Life Cycle + override func viewDidLoad() { super.viewDidLoad() self.setUI() self.setLayout(bottomSheetType) self.setDelegate() self.setBinding() + self.showBottomSheet() if bottomSheetType == .textField { - showBottomSheet() - setupGestureRecognizer() + self.setGesture() self.setAddTarget() } } // MARK: - Methods + @discardableResult func setContentsText(text: String) -> Self { contentsLabel.text = text @@ -128,6 +131,7 @@ final class CustomBottomSheetVC: UIViewController { } // MARK: - UI & Layout + extension CustomBottomSheetVC { private func setUI() { view.addSubview(backgroundView) @@ -228,13 +232,13 @@ extension CustomBottomSheetVC { make.leading.bottom.trailing.equalToSuperview() make.top.equalTo(view.snp.top).offset(topConst) } - + UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseIn, animations: { self.view.layoutIfNeeded() }, completion: nil) } - - private func setupGestureRecognizer() { + + private func setGesture() { let dimmedTap = UITapGestureRecognizer(target: self, action: #selector(dimmedViewTapped(_:))) backgroundView.addGestureRecognizer(dimmedTap) backgroundView.isUserInteractionEnabled = true @@ -245,18 +249,22 @@ extension CustomBottomSheetVC { } // MARK: - @objc Function + extension CustomBottomSheetVC { - @objc private func keyboardWillShow(_ sender: Notification) { - if let keyboardFrame: NSValue = sender.userInfo? [UIResponder.keyboardFrameEndUserInfoKey] as? NSValue { - let keybaordRectangle = keyboardFrame.cgRectValue - let keyboardHeight = keybaordRectangle.height - - self.view.frame.origin.y -= (keyboardHeight - view.safeAreaInsets.bottom) + @objc private func keyboardWillShow(_ sender: Notification) { // 키보드의 높이만큼 화면을 올려줍니다. + if let keyboardFrame: NSValue = sender.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue { + let keyboardRectangle = keyboardFrame.cgRectValue + let keyboardHeight = keyboardRectangle.height + self.view.frame.origin.y -= keyboardHeight } } - @objc private func keyboardWillHide(_ sender: Notification) { - self.view.frame.origin.y = 0 + @objc private func keyboardWillHide(_ sender: Notification) { // 키보드의 높이만큼 화면을 내려줍니다. + if let keyboardFrame: NSValue = sender.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue { + let keyboardRectangle = keyboardFrame.cgRectValue + let keyboardHeight = keyboardRectangle.height + self.view.frame.origin.y += keyboardHeight + } } @objc private func textFieldTextDidChange() { @@ -285,12 +293,13 @@ extension CustomBottomSheetVC { } UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseIn, animations: { + self.backgroundView.alpha = 0 self.view.layoutIfNeeded() }, completion: { _ in if self.presentingViewController != nil { - self.dismiss(animated: false, completion: nil) + self.dismiss(animated: true, completion: nil) } - }) // 하나 이상의 클로저 인수를 전달할때, 후행 클로저 구문을 사용하면 안된다는 경고로 (_) 로 수정 + }) // 하나 이상의 클로저 인수를 전달할때, 후행 클로저 구문을 사용하면 안된다는 경고로 일부 수정 } @@ -300,6 +309,8 @@ extension CustomBottomSheetVC { let velocity = recognizer.velocity(in: bottomSheetView) switch recognizer.state { + case .began: + backgroundView.alpha = 0 // 시작할때 드래그 시작할때 alpha 값 0 case .changed: if velocity.y > 0 { // 아래로만 Pan 가능한 로직 backgroundView.alpha = 0 @@ -310,10 +321,10 @@ extension CustomBottomSheetVC { case .ended: // translation.y 값이 75보다 작으면(작게 이동 시) 뷰의 위치를 다시 원상복구하겠다. = 즉, 다시 y=0인 지점으로 리셋 if translation.y < 75 { + backgroundView.alpha = 0.65 UIView.animate(withDuration: 0.25, animations: { self.view.transform = .identity }) - backgroundView.alpha = 0.65 } else { // translation.y 75 이상이면 해당 화면 dismiss 직접 사용해보니 적절한 값이 75라고 판단 self.backgroundView.alpha = 0 dismiss(animated: true, completion: nil) @@ -325,6 +336,7 @@ extension CustomBottomSheetVC { } // MARK: - UITextFieldDelegate + extension CustomBottomSheetVC: UITextFieldDelegate { func textFieldShouldReturn(_ textField: UITextField) -> Bool { textField.resignFirstResponder() diff --git a/Runnect-iOS/Runnect-iOS/Presentation/CourseDrawing/VC/CourseDrawingVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/CourseDrawing/VC/CourseDrawingVC.swift index c3fe8acf..2b154a26 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/CourseDrawing/VC/CourseDrawingVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/CourseDrawing/VC/CourseDrawingVC.swift @@ -259,10 +259,9 @@ extension CourseDrawingVC { guard handleVisitor() else { return } self.courseName = text self.mapView.capturePathImage() - self.dismiss(animated: true) + self.dismiss(animated: false) } - self.present(bottomSheetVC, animated: true) - // 일단 true로 설정 (background 색 관련하여 여기서 설정할지, 바텀시트에서 설정할지 생각) + self.present(bottomSheetVC, animated: false) } } From ca324ba0d2fce46ed225a0dac9ca802649ce38af Mon Sep 17 00:00:00 2001 From: LeeMyeongJin Date: Mon, 27 Nov 2023 17:24:56 +0900 Subject: [PATCH 08/10] =?UTF-8?q?[Chore]=20#216=20-=20panGesture=20private?= =?UTF-8?q?=20=EC=84=A0=EC=96=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift index 7eddd932..a643c3fd 100644 --- a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift +++ b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift @@ -303,7 +303,7 @@ extension CustomBottomSheetVC { } - @objc func panGesture(_ recognizer: UIPanGestureRecognizer) { + @objc private func panGesture(_ recognizer: UIPanGestureRecognizer) { let translation = recognizer.translation(in: bottomSheetView) let velocity = recognizer.velocity(in: bottomSheetView) From 2d07c79430c603349aaea525e19d065f8da6e9cf Mon Sep 17 00:00:00 2001 From: LeeMyeongJin Date: Tue, 28 Nov 2023 18:09:49 +0900 Subject: [PATCH 09/10] =?UTF-8?q?[Style]=20#186=20-=20background=20Alpha?= =?UTF-8?q?=EA=B0=92=20=EB=AF=B8=EC=84=B8=20=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift index a643c3fd..2b9cd33e 100644 --- a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift +++ b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift @@ -23,7 +23,7 @@ final class CustomBottomSheetVC: UIViewController { private let titleNameMaxLength = 20 private let bottomHeight: CGFloat = 206 - private let backgroundView = UIView().then { $0.backgroundColor = .g1.withAlphaComponent(0.65) } + private let backgroundView = UIView().then { $0.backgroundColor = .g1.withAlphaComponent(0.6) } private var cancelBag = CancelBag() private var bottomSheetType: SheetType! @@ -324,6 +324,7 @@ extension CustomBottomSheetVC { backgroundView.alpha = 0.65 UIView.animate(withDuration: 0.25, animations: { self.view.transform = .identity + self.backgroundView.alpha = 0.6 }) } else { // translation.y 75 이상이면 해당 화면 dismiss 직접 사용해보니 적절한 값이 75라고 판단 self.backgroundView.alpha = 0 From 86512745c5a596f32ab8dc2c883797419ac496d2 Mon Sep 17 00:00:00 2001 From: LeeMyeongJin Date: Tue, 28 Nov 2023 18:11:11 +0900 Subject: [PATCH 10/10] =?UTF-8?q?[Feat]=20#216=20-=20=EB=B0=94=ED=85=80?= =?UTF-8?q?=EC=8B=9C=ED=8A=B8=20=EC=B5=9C=EC=A2=85=20=EC=9E=91=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 이제 백그라운드도 문제없이 작용합니다. 추가로 위로 스와이프 되는 코드도 추가하여 내리다가 다시 올릴 수 있습니다. --- .../UIComponents/CustomBottomSheetVC.swift | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift index 2b9cd33e..18be608e 100644 --- a/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift +++ b/Runnect-iOS/Runnect-iOS/Global/UIComponents/CustomBottomSheetVC.swift @@ -244,7 +244,7 @@ extension CustomBottomSheetVC { backgroundView.isUserInteractionEnabled = true let panGesture = UIPanGestureRecognizer(target: self, action: #selector(panGesture(_:))) - view.addGestureRecognizer(panGesture) + bottomSheetView.addGestureRecognizer(panGesture) } } @@ -311,21 +311,29 @@ extension CustomBottomSheetVC { switch recognizer.state { case .began: backgroundView.alpha = 0 // 시작할때 드래그 시작할때 alpha 값 0 + recognizer.setTranslation(CGPoint.zero, in: bottomSheetView) case .changed: - if velocity.y > 0 { // 아래로만 Pan 가능한 로직 + if velocity.y > 0 && translation.y > 0 { // 아래로만 Pan 가능한 로직 , 여기서 translation.y > 0 이거 추가 안해주면 재밌게 에니메이션이 움직인다.. backgroundView.alpha = 0 UIView.animate(withDuration: 0.25, animations: { self.view.transform = CGAffineTransform(translationX: 0, y: translation.y) }) + } else if velocity.y < 0 && translation.y > 0 { + // 위로도 움직이게는 하지만, 한계설정을 바텀시트의 높이로 설정, 즉 위쪽으로 하나도 못 움직이게 설정 ( translation.y > 0 ) 한계점 설정 + UIView.animate(withDuration: 0.25, animations: { + self.view.transform = CGAffineTransform(translationX: 0, y: translation.y) + }) } case .ended: - // translation.y 값이 75보다 작으면(작게 이동 시) 뷰의 위치를 다시 원상복구하겠다. = 즉, 다시 y=0인 지점으로 리셋 + // 끝나는 지점의 translation.y 값이 75보다 작으면(작게 이동 시) 뷰의 위치를 다시 원상복구하겠다. = 즉, 다시 y=0인 지점으로 리셋 if translation.y < 75 { - backgroundView.alpha = 0.65 UIView.animate(withDuration: 0.25, animations: { self.view.transform = .identity + }, completion: { _ in + // 애니메이션이 끝나면 실행될 코드 self.backgroundView.alpha = 0.6 }) + recognizer.setTranslation(CGPoint.zero, in: bottomSheetView) } else { // translation.y 75 이상이면 해당 화면 dismiss 직접 사용해보니 적절한 값이 75라고 판단 self.backgroundView.alpha = 0 dismiss(animated: true, completion: nil)