From 3c2590379e281ceca3ab7079ac1651be0413b014 Mon Sep 17 00:00:00 2001 From: tngusmiso Date: Thu, 9 Feb 2023 01:14:11 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[FEAT][#7]=20AttandanceDetailViewController?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1,=20=EC=BD=94=EB=93=9C=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=20=ED=99=94=EB=A9=B4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- momoIOS.xcodeproj/project.pbxproj | 20 +++- .../ViewController/MainViewController.swift | 3 +- .../AttendanceCodeDetailViewController.swift | 112 ++++++++++++++++++ 3 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 momoIOS/UserSide/AttendanceCodeDetail/AttendanceCodeDetailViewController.swift diff --git a/momoIOS.xcodeproj/project.pbxproj b/momoIOS.xcodeproj/project.pbxproj index 1176ff2..4c8faad 100644 --- a/momoIOS.xcodeproj/project.pbxproj +++ b/momoIOS.xcodeproj/project.pbxproj @@ -7,9 +7,10 @@ objects = { /* Begin PBXBuildFile section */ - 3A5AC30A2989784A0080323A /* AbsenceModalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A5AC3092989784A0080323A /* AbsenceModalViewController.swift */; }; 3A5AC31029898B330080323A /* UIButton+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A5AC30F29898B330080323A /* UIButton+Extension.swift */; }; 3A75FC10298827BE00B36A46 /* MainAttendanceCodeCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A75FC0F298827BE00B36A46 /* MainAttendanceCodeCell.swift */; }; + 3A8E2DDF2997697E00D5476A /* AttendanceCodeDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A8E2DDE2997697E00D5476A /* AttendanceCodeDetailViewController.swift */; }; + 3A8E2DE129976A8F00D5476A /* AbsenceModalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A8E2DE029976A8F00D5476A /* AbsenceModalViewController.swift */; }; 3AA713C929884007006F922F /* MainAttendanceDoneCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA713C829884007006F922F /* MainAttendanceDoneCell.swift */; }; 3AA713D1298946FF006F922F /* UIColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA713D0298946FF006F922F /* UIColor+Extension.swift */; }; 3ABBF74829975801004D4D0B /* NotActiveSessionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABBF74729975801004D4D0B /* NotActiveSessionCell.swift */; }; @@ -47,9 +48,10 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 3A5AC3092989784A0080323A /* AbsenceModalViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AbsenceModalViewController.swift; sourceTree = ""; }; 3A5AC30F29898B330080323A /* UIButton+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIButton+Extension.swift"; sourceTree = ""; }; 3A75FC0F298827BE00B36A46 /* MainAttendanceCodeCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainAttendanceCodeCell.swift; sourceTree = ""; }; + 3A8E2DDE2997697E00D5476A /* AttendanceCodeDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttendanceCodeDetailViewController.swift; sourceTree = ""; }; + 3A8E2DE029976A8F00D5476A /* AbsenceModalViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AbsenceModalViewController.swift; sourceTree = ""; }; 3AA713C829884007006F922F /* MainAttendanceDoneCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainAttendanceDoneCell.swift; sourceTree = ""; }; 3AA713D0298946FF006F922F /* UIColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Extension.swift"; sourceTree = ""; }; 3ABBF74729975801004D4D0B /* NotActiveSessionCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotActiveSessionCell.swift; sourceTree = ""; }; @@ -99,6 +101,14 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 3A8E2DDC2997697E00D5476A /* AttendanceCodeDetail */ = { + isa = PBXGroup; + children = ( + 3A8E2DDE2997697E00D5476A /* AttendanceCodeDetailViewController.swift */, + ); + path = AttendanceCodeDetail; + sourceTree = ""; + }; 3ABBF73F29975082004D4D0B /* Common */ = { isa = PBXGroup; children = ( @@ -111,7 +121,7 @@ 3ABBF742299750A4004D4D0B /* UI */ = { isa = PBXGroup; children = ( - 3A5AC3092989784A0080323A /* AbsenceModalViewController.swift */, + 3A8E2DE029976A8F00D5476A /* AbsenceModalViewController.swift */, BF43B57729951F0C0026DCE3 /* ProfileView.swift */, ); path = UI; @@ -145,6 +155,7 @@ isa = PBXGroup; children = ( 3ABBF743299752EB004D4D0B /* Main */, + 3A8E2DDC2997697E00D5476A /* AttendanceCodeDetail */, BF9988FA298AD002005723C7 /* PersonalInformation */, ); path = UserSide; @@ -373,14 +384,15 @@ E8D5C3F32984FC23003D1AD0 /* SceneDelegate.swift in Sources */, 3A75FC10298827BE00B36A46 /* MainAttendanceCodeCell.swift in Sources */, E83238F1298506A000DC83C2 /* MainViewController.swift in Sources */, - 3A5AC30A2989784A0080323A /* AbsenceModalViewController.swift in Sources */, BF998900298BB0D3005723C7 /* InputMemberInfoController.swift in Sources */, BF0408632987B3AA00F1129B /* LoginController.swift in Sources */, BF6EC77F298D1B2E00F4B170 /* AttendanceResultCell.swift in Sources */, BF04086B2987E34800F1129B /* AuthCommonConstants.swift in Sources */, 3A5AC31029898B330080323A /* UIButton+Extension.swift in Sources */, BF43B57829951F0C0026DCE3 /* ProfileView.swift in Sources */, + 3A8E2DDF2997697E00D5476A /* AttendanceCodeDetailViewController.swift in Sources */, E8207934298A22D000B36FC9 /* MainSessionInfoCell.swift in Sources */, + 3A8E2DE129976A8F00D5476A /* AbsenceModalViewController.swift in Sources */, 3ABBF74829975801004D4D0B /* NotActiveSessionCell.swift in Sources */, 3ABBF75229975EDA004D4D0B /* AdminSessionTableViewController.swift in Sources */, E8207932298A163400B36FC9 /* UIView+Extension.swift in Sources */, diff --git a/momoIOS/Main/ViewController/MainViewController.swift b/momoIOS/Main/ViewController/MainViewController.swift index 11079a8..900425c 100644 --- a/momoIOS/Main/ViewController/MainViewController.swift +++ b/momoIOS/Main/ViewController/MainViewController.swift @@ -66,7 +66,8 @@ class MainViewController: UIViewController { // MARK: - Action private func goToAttendanceVC() { - self.navigationController?.popViewController(animated: true) + let attandanceVC = AttendanceDetailViewController() + self.navigationController?.pushViewController(attandanceVC, animated: true) } private func showAbsenceModal() { diff --git a/momoIOS/UserSide/AttendanceCodeDetail/AttendanceCodeDetailViewController.swift b/momoIOS/UserSide/AttendanceCodeDetail/AttendanceCodeDetailViewController.swift new file mode 100644 index 0000000..6968c2c --- /dev/null +++ b/momoIOS/UserSide/AttendanceCodeDetail/AttendanceCodeDetailViewController.swift @@ -0,0 +1,112 @@ +// +// AttendanceCodeDetailViewController.swift +// momoIOS +// +// Created by 임수현 on 2023/02/09. +// + +import UIKit + +class AttendanceCodeDetailViewController: UIViewController { + private let backgroundView: UIView = UIView() + private let titleLabel: UILabel = UILabel() + private let codeContainerView: UIStackView = UIStackView() + private let codeTextFields: [UITextField] = [UITextField(), UITextField(), UITextField(), UITextField()] + private let descriptionLabel: UILabel = UILabel() + + // MARK: - Lifecycle + override func viewDidLoad() { + super.viewDidLoad() + + self.setupViews() + self.setupLayout() + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + + self.navigationController?.setNavigationBarHidden(false, animated: animated) + self.setupNavigation() + } + + // MARK: - Setup + private func setupNavigation() { + + } + + private func setupViews() { + self.view.backgroundColor = .white + + self.backgroundView.backgroundColor = .rgba(128, 135, 201, 1) + self.backgroundView.layer.cornerRadius = 12 + + self.titleLabel.text = "출석체크 코드 입력" + self.titleLabel.font = .systemFont(ofSize: 17, weight: .bold) + self.titleLabel.textColor = .white + + self.codeContainerView.axis = .horizontal + self.codeContainerView.spacing = 14 + self.codeContainerView.distribution = .fillEqually + + self.codeTextFields.forEach { textField in + textField.backgroundColor = .clear + textField.textAlignment = .center + textField.textColor = .white + textField.font = .systemFont(ofSize: 32, weight: .medium) + textField.keyboardType = .numberPad +// textField.delegate = self +// textField.dataSource = self + } + + self.descriptionLabel.text = "운영진이 공지해준 출석체크 코드를 입력해주세요!" + self.descriptionLabel.font = .systemFont(ofSize: 12) + self.descriptionLabel.textColor = .white.withAlphaComponent(0.67) + self.backgroundView.addSubview(self.descriptionLabel) + } + + // MARK: - Layout + private func setupLayout() { + self.view.addSubview(self.backgroundView) + self.backgroundView.snp.makeConstraints { make in + make.top.equalTo(self.view.safeAreaLayoutGuide).inset(30) + make.leading.trailing.equalTo(self.view.safeAreaLayoutGuide).inset(24) + } + + self.backgroundView.addSubview(self.titleLabel) + self.titleLabel.snp.makeConstraints { make in + make.top.equalToSuperview().inset(35) + make.centerX.equalToSuperview() + } + + self.backgroundView.addSubview(self.codeContainerView) + self.codeContainerView.snp.makeConstraints { make in + make.top.equalTo(self.titleLabel.snp.bottom).offset(54) + make.leading.trailing.equalToSuperview().inset(53) + } + + self.codeTextFields.forEach { textField in + let codeView = UIStackView() + codeView.axis = .vertical + let view = UIView() + view.backgroundColor = .white + + codeView.addArrangedSubviews(textField, view) + textField.snp.makeConstraints { make in + make.width.equalTo(45) + make.height.equalTo(70) + } + view.snp.makeConstraints { make in + make.width.equalTo(textField) + make.height.equalTo(1) + } + + self.codeContainerView.addArrangedSubview(codeView) + } + self.backgroundView.addSubview(self.descriptionLabel) + self.descriptionLabel.snp.makeConstraints { make in + make.top.equalTo(self.codeContainerView.snp.bottom).offset(33) + make.centerX.equalToSuperview() + make.bottom.equalToSuperview().inset(42) + } + } +} From 2ee20ab36a54dfc1cb01e9b790489b8d8c6c61c5 Mon Sep 17 00:00:00 2001 From: tngusmiso Date: Sat, 11 Feb 2023 01:41:26 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[FEAT][#7]=20AttandanceDetailViewController?= =?UTF-8?q?=20=EC=B6=9C=EC=84=9D=EB=B2=84=ED=8A=BC=20=EC=B6=94=EA=B0=80,?= =?UTF-8?q?=20=ED=82=A4=EB=B3=B4=EB=93=9C=EC=97=90=20=EB=94=B0=EB=9D=BC=20?= =?UTF-8?q?=EB=B2=84=ED=8A=BC=20=EC=9D=B4=EB=8F=99=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Common/Extensions/UIView+Extension.swift | 21 +++++++ .../AttendanceCodeDetailViewController.swift | 55 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/momoIOS/Common/Extensions/UIView+Extension.swift b/momoIOS/Common/Extensions/UIView+Extension.swift index db1abd7..194dc99 100644 --- a/momoIOS/Common/Extensions/UIView+Extension.swift +++ b/momoIOS/Common/Extensions/UIView+Extension.swift @@ -13,4 +13,25 @@ extension UIView { func addSubviews(_ views: UIView...) { views.forEach { addSubview($0) } } + + /// 키보드 움직임에 따라서 움직이도록 함. + func moveWithKeyboard(willShow keyboardWillShow: Bool, notification: NSNotification, safeAreaBottomInset: CGFloat = 0) { + guard let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue, + let keyboardDuration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double, + let keyboardcurveValue = notification.userInfo?[UIResponder.keyboardAnimationCurveUserInfoKey] as? UInt + else { return } + + let keyboardHeight = keyboardSize.height + let curveOption = UIView.AnimationOptions(rawValue: keyboardcurveValue << 16) + + if keyboardWillShow { + UIView.animate(withDuration: keyboardDuration, delay: 0, options: [curveOption]) { [weak self] in + self?.transform = CGAffineTransform(translationX: 0, y: -keyboardHeight + safeAreaBottomInset) + } + } else { + UIView.animate(withDuration: keyboardDuration, delay: 0, options: [curveOption]) { [weak self] in + self?.transform = .identity + } + } + } } diff --git a/momoIOS/UserSide/AttendanceCodeDetail/AttendanceCodeDetailViewController.swift b/momoIOS/UserSide/AttendanceCodeDetail/AttendanceCodeDetailViewController.swift index 6968c2c..f295d1c 100644 --- a/momoIOS/UserSide/AttendanceCodeDetail/AttendanceCodeDetailViewController.swift +++ b/momoIOS/UserSide/AttendanceCodeDetail/AttendanceCodeDetailViewController.swift @@ -13,11 +13,13 @@ class AttendanceCodeDetailViewController: UIViewController { private let codeContainerView: UIStackView = UIStackView() private let codeTextFields: [UITextField] = [UITextField(), UITextField(), UITextField(), UITextField()] private let descriptionLabel: UILabel = UILabel() + private let attendButton: UIButton = UIButton() // MARK: - Lifecycle override func viewDidLoad() { super.viewDidLoad() + self.setupKeyboardNotifications() self.setupViews() self.setupLayout() } @@ -29,7 +31,25 @@ class AttendanceCodeDetailViewController: UIViewController { self.setupNavigation() } + override func touchesBegan(_ touches: Set, with event: UIEvent?) { + self.view.endEditing(true) + } + // MARK: - Setup + private func setupKeyboardNotifications() { + NotificationCenter.default.addObserver( + self, + selector: #selector(self.keyboardWillShow), + name: UIResponder.keyboardWillShowNotification, + object: nil) + + NotificationCenter.default.addObserver( + self, + selector: #selector(self.keyboardWillHide), + name: UIResponder.keyboardWillHideNotification, + object: nil) + } + private func setupNavigation() { } @@ -62,6 +82,9 @@ class AttendanceCodeDetailViewController: UIViewController { self.descriptionLabel.font = .systemFont(ofSize: 12) self.descriptionLabel.textColor = .white.withAlphaComponent(0.67) self.backgroundView.addSubview(self.descriptionLabel) + + self.attendButton.setTitle("출석하기", size: 16, weight: .bold, color: .white) + self.attendButton.configurate(bgColor: .rgba(56, 56, 56, 1), cornerRadius: 7, padding: 10) } // MARK: - Layout @@ -108,5 +131,37 @@ class AttendanceCodeDetailViewController: UIViewController { make.centerX.equalToSuperview() make.bottom.equalToSuperview().inset(42) } + + self.view.addSubview(self.attendButton) + self.attendButton.snp.makeConstraints { make in + make.leading.trailing.equalTo(self.view.safeAreaLayoutGuide).inset(24) + make.bottom.equalTo(self.view.safeAreaLayoutGuide).inset(28) + make.height.equalTo(54) + } + } + + // MARK: - Actions + @objc func keyboardWillShow(_ notification: NSNotification) { + if self.isEditingCode { + self.attendButton.moveWithKeyboard( + willShow: true, + notification: notification, + safeAreaBottomInset: self.view.safeAreaInsets.bottom + ) + } + } + + @objc func keyboardWillHide(_ notification: NSNotification) { + self.attendButton.moveWithKeyboard( + willShow: false, + notification: notification, + safeAreaBottomInset: self.view.safeAreaInsets.bottom + ) + } + + // MARK: - Logics + private var isEditingCode: Bool { + let textFileds = self.codeTextFields + return textFileds[0].isEditing || textFileds[1].isEditing || textFileds[2].isEditing || textFileds[3].isEditing } } From a430a9b4cc5c3385a306d12d611e3707dde47f27 Mon Sep 17 00:00:00 2001 From: tngusmiso Date: Sat, 11 Feb 2023 04:34:00 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[FEAT][#7]=20=EC=B6=9C=EC=84=9D=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EC=9E=85=EB=A0=A5=EB=9E=80=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- momoIOS.xcodeproj/project.pbxproj | 8 ++ .../Extensions/Collection+Extension.swift | 14 ++++ .../Common/Extensions/String+Extension.swift | 40 +++++++++ .../AttendanceCodeDetailViewController.swift | 82 +++++++++++++++++-- 4 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 momoIOS/Common/Extensions/Collection+Extension.swift create mode 100644 momoIOS/Common/Extensions/String+Extension.swift diff --git a/momoIOS.xcodeproj/project.pbxproj b/momoIOS.xcodeproj/project.pbxproj index 4c8faad..3a6a167 100644 --- a/momoIOS.xcodeproj/project.pbxproj +++ b/momoIOS.xcodeproj/project.pbxproj @@ -17,6 +17,8 @@ 3ABBF75129975EDA004D4D0B /* AdminSessionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABBF74E29975ED9004D4D0B /* AdminSessionCell.swift */; }; 3ABBF75229975EDA004D4D0B /* AdminSessionTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABBF74F29975ED9004D4D0B /* AdminSessionTableViewController.swift */; }; 3ABBF75329975EDA004D4D0B /* AddSessionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABBF75029975ED9004D4D0B /* AddSessionViewController.swift */; }; + 3AE3323229976C2E0024C0C5 /* Collection+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE3323029976C2E0024C0C5 /* Collection+Extension.swift */; }; + 3AE3323329976C2E0024C0C5 /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE3323129976C2E0024C0C5 /* String+Extension.swift */; }; BF0408632987B3AA00F1129B /* LoginController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0408622987B3AA00F1129B /* LoginController.swift */; }; BF04086B2987E34800F1129B /* AuthCommonConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF04086A2987E34800F1129B /* AuthCommonConstants.swift */; }; BF04086D2987E38C00F1129B /* RegistrationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF04086C2987E38C00F1129B /* RegistrationController.swift */; }; @@ -58,6 +60,8 @@ 3ABBF74E29975ED9004D4D0B /* AdminSessionCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdminSessionCell.swift; sourceTree = ""; }; 3ABBF74F29975ED9004D4D0B /* AdminSessionTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdminSessionTableViewController.swift; sourceTree = ""; }; 3ABBF75029975ED9004D4D0B /* AddSessionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddSessionViewController.swift; sourceTree = ""; }; + 3AE3323029976C2E0024C0C5 /* Collection+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Collection+Extension.swift"; sourceTree = ""; }; + 3AE3323129976C2E0024C0C5 /* String+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Extension.swift"; sourceTree = ""; }; BF0408622987B3AA00F1129B /* LoginController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginController.swift; sourceTree = ""; }; BF04086A2987E34800F1129B /* AuthCommonConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthCommonConstants.swift; sourceTree = ""; }; BF04086C2987E38C00F1129B /* RegistrationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegistrationController.swift; sourceTree = ""; }; @@ -231,10 +235,12 @@ E8207930298A163400B36FC9 /* Extensions */ = { isa = PBXGroup; children = ( + 3AE3323029976C2E0024C0C5 /* Collection+Extension.swift */, 3A5AC30F29898B330080323A /* UIButton+Extension.swift */, 3AA713D0298946FF006F922F /* UIColor+Extension.swift */, BFB8431E298CFF9200BA11EC /* UIStackView+Extension.swift */, E8207931298A163400B36FC9 /* UIView+Extension.swift */, + 3AE3323129976C2E0024C0C5 /* String+Extension.swift */, ); path = Extensions; sourceTree = ""; @@ -398,6 +404,7 @@ E8207932298A163400B36FC9 /* UIView+Extension.swift in Sources */, BFB8431F298CFF9200BA11EC /* UIStackView+Extension.swift in Sources */, 3ABBF75129975EDA004D4D0B /* AdminSessionCell.swift in Sources */, + 3AE3323229976C2E0024C0C5 /* Collection+Extension.swift in Sources */, E820792D298A137700B36FC9 /* MainSessionTimeCell.swift in Sources */, E820792B298A119900B36FC9 /* MainSessionDetailCell.swift in Sources */, E8207936298A248200B36FC9 /* MainSessionNoInfoCell.swift in Sources */, @@ -406,6 +413,7 @@ 3AA713C929884007006F922F /* MainAttendanceDoneCell.swift in Sources */, BF43B57A29952AFF0026DCE3 /* MoimSettingCell.swift in Sources */, E820792F298A138500B36FC9 /* MainSessionAbsentCell.swift in Sources */, + 3AE3323329976C2E0024C0C5 /* String+Extension.swift in Sources */, BF4310FA298C525900270DBF /* AttendanceHistoryCell.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/momoIOS/Common/Extensions/Collection+Extension.swift b/momoIOS/Common/Extensions/Collection+Extension.swift new file mode 100644 index 0000000..cb90958 --- /dev/null +++ b/momoIOS/Common/Extensions/Collection+Extension.swift @@ -0,0 +1,14 @@ +// +// Collection+Extension.swift +// momoIOS +// +// Created by 임수현 on 2023/02/11. +// + +import Foundation + +extension Collection { + subscript (safe index: Index) -> Element? { + return indices.contains(index) ? self[index] : nil + } +} diff --git a/momoIOS/Common/Extensions/String+Extension.swift b/momoIOS/Common/Extensions/String+Extension.swift new file mode 100644 index 0000000..d1872ce --- /dev/null +++ b/momoIOS/Common/Extensions/String+Extension.swift @@ -0,0 +1,40 @@ +// +// String+Extension.swift +// momoIOS +// +// Created by 임수현 on 2023/02/11. +// + +import Foundation + +extension String { + subscript (safe index: Int) -> String? { + guard self.count > index else { return nil } + let index = self.index(self.startIndex, offsetBy: index) + return "\(self[index])" + } + + subscript (range: Range) -> String? { + let fromIndex = self.index(self.startIndex, offsetBy: max(0, range.lowerBound)) + let toIndex = self.index(self.startIndex, offsetBy: min(range.upperBound, self.count)) + return String(self[fromIndex..) -> String { + let fromIndex = self.index(self.startIndex, offsetBy: range.startIndex) + let toIndex = self.index(self.startIndex, offsetBy: range.endIndex) + return String(self[fromIndex.. String? { + guard let range = Range(range, in: self) else { return nil } + return self.replacingCharacters(in: range, with: string) + } + + var isBackspace: Bool { + if let char = self.cString(using: String.Encoding.utf8) { + return strcmp(char, "\\b") == -92 + } + return false + } +} diff --git a/momoIOS/UserSide/AttendanceCodeDetail/AttendanceCodeDetailViewController.swift b/momoIOS/UserSide/AttendanceCodeDetail/AttendanceCodeDetailViewController.swift index f295d1c..90537b0 100644 --- a/momoIOS/UserSide/AttendanceCodeDetail/AttendanceCodeDetailViewController.swift +++ b/momoIOS/UserSide/AttendanceCodeDetail/AttendanceCodeDetailViewController.swift @@ -39,13 +39,13 @@ class AttendanceCodeDetailViewController: UIViewController { private func setupKeyboardNotifications() { NotificationCenter.default.addObserver( self, - selector: #selector(self.keyboardWillShow), + selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil) NotificationCenter.default.addObserver( self, - selector: #selector(self.keyboardWillHide), + selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil) } @@ -74,8 +74,7 @@ class AttendanceCodeDetailViewController: UIViewController { textField.textColor = .white textField.font = .systemFont(ofSize: 32, weight: .medium) textField.keyboardType = .numberPad -// textField.delegate = self -// textField.dataSource = self + textField.delegate = self } self.descriptionLabel.text = "운영진이 공지해준 출석체크 코드를 입력해주세요!" @@ -139,8 +138,51 @@ class AttendanceCodeDetailViewController: UIViewController { make.height.equalTo(54) } } +} + +// MARK: - UITextFieldDelegate +extension AttendanceCodeDetailViewController: UITextFieldDelegate { + func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { + let currentText = textField.text ?? "" + let newText = range.lowerBound == 0 ? string : currentText.replaced(string, in: range) ?? "" + + if newText.count == 0 { + textField.text = newText + self.prevTextField(textField)?.becomeFirstResponder() + } else { + self.fillTextField(textField, with: newText) + } + return false + } + + // MARK: - TextField Values + private var isEditingCode: Bool { + for textField in self.codeTextFields where textField.isEditing == true { + return true + } + return false + } + + private func textFieldIndex(of textField: UITextField) -> Int? { + for index in 0.. UITextField? { + guard let index = self.textFieldIndex(of: textField) else { return nil } + return self.codeTextFields[safe: index - 1] + } + + private func nextTextField(_ textField: UITextField) -> UITextField? { + guard let index = self.textFieldIndex(of: textField) else { return nil } + return self.codeTextFields[safe: index + 1] + } + + // MARK: - TextField Actions @objc func keyboardWillShow(_ notification: NSNotification) { if self.isEditingCode { self.attendButton.moveWithKeyboard( @@ -159,9 +201,31 @@ class AttendanceCodeDetailViewController: UIViewController { ) } - // MARK: - Logics - private var isEditingCode: Bool { - let textFileds = self.codeTextFields - return textFileds[0].isEditing || textFileds[1].isEditing || textFileds[2].isEditing || textFileds[3].isEditing + private func fillTextField(_ textField: UITextField, with string: String) { + let string = string.trimmingCharacters(in: CharacterSet(charactersIn: "0123456789.").inverted) + guard !string.isEmpty else { return } + textField.text = string[safe: 0] + + guard let nextTextField = self.nextTextField(textField) else { return } + nextTextField.becomeFirstResponder() + if nextTextField.text?.isEmpty == false { + self.setCursor(of: nextTextField, at: 0) + } + self.fillTextField(nextTextField, with: string[1.. Date: Sat, 11 Feb 2023 11:06:44 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[FEAT][#7]=20=EC=B6=9C=EC=84=9D=EC=B2=B4?= =?UTF-8?q?=ED=81=AC=20=EC=BD=94=EB=93=9C=20=EC=9E=85=EB=A0=A5=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=9D=BC=20=EC=B6=9C=EC=84=9D=EB=B2=84=ED=8A=BC=20Ena?= =?UTF-8?q?bled=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Optional+Extension 추가 : isNil, isNotNil, isEmptyOrNil - textField 입력될 때 마다 버튼 enabled 체크 - 버튼 enabled 값에 따라 configuration 변경 - MainAttendanceCodeCell 클릭 시 이동 로직 추가 --- momoIOS.xcodeproj/project.pbxproj | 24 +++++--- .../Extensions/Optional+Extension.swift | 23 ++++++++ .../UINavigationController+Extension.swift | 21 +++++++ .../AttendanceCodeDetailViewController.swift | 57 ++++++++++++++++++- .../UserSide/Main/MainViewController.swift | 3 +- 5 files changed, 116 insertions(+), 12 deletions(-) create mode 100644 momoIOS/Common/Extensions/Optional+Extension.swift create mode 100644 momoIOS/Common/Extensions/UINavigationController+Extension.swift diff --git a/momoIOS.xcodeproj/project.pbxproj b/momoIOS.xcodeproj/project.pbxproj index 3a6a167..b005022 100644 --- a/momoIOS.xcodeproj/project.pbxproj +++ b/momoIOS.xcodeproj/project.pbxproj @@ -17,8 +17,10 @@ 3ABBF75129975EDA004D4D0B /* AdminSessionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABBF74E29975ED9004D4D0B /* AdminSessionCell.swift */; }; 3ABBF75229975EDA004D4D0B /* AdminSessionTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABBF74F29975ED9004D4D0B /* AdminSessionTableViewController.swift */; }; 3ABBF75329975EDA004D4D0B /* AddSessionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABBF75029975ED9004D4D0B /* AddSessionViewController.swift */; }; - 3AE3323229976C2E0024C0C5 /* Collection+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE3323029976C2E0024C0C5 /* Collection+Extension.swift */; }; - 3AE3323329976C2E0024C0C5 /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE3323129976C2E0024C0C5 /* String+Extension.swift */; }; + 3ABEDB7129976EF100F9BF1C /* UINavigationController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABEDB6F29976EF100F9BF1C /* UINavigationController+Extension.swift */; }; + 3ABEDB7229976EF100F9BF1C /* Optional+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABEDB7029976EF100F9BF1C /* Optional+Extension.swift */; }; + 3ABEDB742997719000F9BF1C /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABEDB732997719000F9BF1C /* String+Extension.swift */; }; + 3ABEDB76299771A900F9BF1C /* Collection+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABEDB75299771A900F9BF1C /* Collection+Extension.swift */; }; BF0408632987B3AA00F1129B /* LoginController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0408622987B3AA00F1129B /* LoginController.swift */; }; BF04086B2987E34800F1129B /* AuthCommonConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF04086A2987E34800F1129B /* AuthCommonConstants.swift */; }; BF04086D2987E38C00F1129B /* RegistrationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF04086C2987E38C00F1129B /* RegistrationController.swift */; }; @@ -60,8 +62,10 @@ 3ABBF74E29975ED9004D4D0B /* AdminSessionCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdminSessionCell.swift; sourceTree = ""; }; 3ABBF74F29975ED9004D4D0B /* AdminSessionTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdminSessionTableViewController.swift; sourceTree = ""; }; 3ABBF75029975ED9004D4D0B /* AddSessionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddSessionViewController.swift; sourceTree = ""; }; - 3AE3323029976C2E0024C0C5 /* Collection+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Collection+Extension.swift"; sourceTree = ""; }; - 3AE3323129976C2E0024C0C5 /* String+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Extension.swift"; sourceTree = ""; }; + 3ABEDB6F29976EF100F9BF1C /* UINavigationController+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UINavigationController+Extension.swift"; sourceTree = ""; }; + 3ABEDB7029976EF100F9BF1C /* Optional+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Optional+Extension.swift"; sourceTree = ""; }; + 3ABEDB732997719000F9BF1C /* String+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Extension.swift"; sourceTree = ""; }; + 3ABEDB75299771A900F9BF1C /* Collection+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Collection+Extension.swift"; sourceTree = ""; }; BF0408622987B3AA00F1129B /* LoginController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginController.swift; sourceTree = ""; }; BF04086A2987E34800F1129B /* AuthCommonConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthCommonConstants.swift; sourceTree = ""; }; BF04086C2987E38C00F1129B /* RegistrationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegistrationController.swift; sourceTree = ""; }; @@ -235,12 +239,14 @@ E8207930298A163400B36FC9 /* Extensions */ = { isa = PBXGroup; children = ( - 3AE3323029976C2E0024C0C5 /* Collection+Extension.swift */, + 3ABEDB75299771A900F9BF1C /* Collection+Extension.swift */, + 3ABEDB7029976EF100F9BF1C /* Optional+Extension.swift */, + 3ABEDB732997719000F9BF1C /* String+Extension.swift */, 3A5AC30F29898B330080323A /* UIButton+Extension.swift */, 3AA713D0298946FF006F922F /* UIColor+Extension.swift */, + 3ABEDB6F29976EF100F9BF1C /* UINavigationController+Extension.swift */, BFB8431E298CFF9200BA11EC /* UIStackView+Extension.swift */, E8207931298A163400B36FC9 /* UIView+Extension.swift */, - 3AE3323129976C2E0024C0C5 /* String+Extension.swift */, ); path = Extensions; sourceTree = ""; @@ -404,17 +410,19 @@ E8207932298A163400B36FC9 /* UIView+Extension.swift in Sources */, BFB8431F298CFF9200BA11EC /* UIStackView+Extension.swift in Sources */, 3ABBF75129975EDA004D4D0B /* AdminSessionCell.swift in Sources */, - 3AE3323229976C2E0024C0C5 /* Collection+Extension.swift in Sources */, E820792D298A137700B36FC9 /* MainSessionTimeCell.swift in Sources */, E820792B298A119900B36FC9 /* MainSessionDetailCell.swift in Sources */, E8207936298A248200B36FC9 /* MainSessionNoInfoCell.swift in Sources */, BF43B57629951EAF0026DCE3 /* MoimManagementController.swift in Sources */, + 3ABEDB742997719000F9BF1C /* String+Extension.swift in Sources */, 3AA713D1298946FF006F922F /* UIColor+Extension.swift in Sources */, 3AA713C929884007006F922F /* MainAttendanceDoneCell.swift in Sources */, BF43B57A29952AFF0026DCE3 /* MoimSettingCell.swift in Sources */, E820792F298A138500B36FC9 /* MainSessionAbsentCell.swift in Sources */, - 3AE3323329976C2E0024C0C5 /* String+Extension.swift in Sources */, BF4310FA298C525900270DBF /* AttendanceHistoryCell.swift in Sources */, + 3ABEDB76299771A900F9BF1C /* Collection+Extension.swift in Sources */, + 3ABEDB7129976EF100F9BF1C /* UINavigationController+Extension.swift in Sources */, + 3ABEDB7229976EF100F9BF1C /* Optional+Extension.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/momoIOS/Common/Extensions/Optional+Extension.swift b/momoIOS/Common/Extensions/Optional+Extension.swift new file mode 100644 index 0000000..2be162c --- /dev/null +++ b/momoIOS/Common/Extensions/Optional+Extension.swift @@ -0,0 +1,23 @@ +// +// Optional+Extension.swift +// momoIOS +// +// Created by 임수현 on 2023/02/11. +// + +import Foundation + +extension Optional { + var isNil: Bool { + self == nil + } + var isNotNil: Bool { + self != nil + } +} + +extension String? { + var isEmptyOrNil: Bool { + self?.isEmpty == true || self.isNil + } +} diff --git a/momoIOS/Common/Extensions/UINavigationController+Extension.swift b/momoIOS/Common/Extensions/UINavigationController+Extension.swift new file mode 100644 index 0000000..cc2658b --- /dev/null +++ b/momoIOS/Common/Extensions/UINavigationController+Extension.swift @@ -0,0 +1,21 @@ +// +// UINavigationController+Extension.swift +// momoIOS +// +// Created by 임수현 on 2023/02/11. +// + +import UIKit + +extension UINavigationController: ObservableObject, UIGestureRecognizerDelegate { + override open func viewDidLoad() { + super.viewDidLoad() + + // backButton을 임의로 변경하면 swipe back 동작이 되지 않기 떄문에 gestureRecognizer를 설정하여 동작하도록 함. + interactivePopGestureRecognizer?.delegate = self + } + + public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { + return viewControllers.count > 1 + } +} diff --git a/momoIOS/UserSide/AttendanceCodeDetail/AttendanceCodeDetailViewController.swift b/momoIOS/UserSide/AttendanceCodeDetail/AttendanceCodeDetailViewController.swift index 90537b0..b291188 100644 --- a/momoIOS/UserSide/AttendanceCodeDetail/AttendanceCodeDetailViewController.swift +++ b/momoIOS/UserSide/AttendanceCodeDetail/AttendanceCodeDetailViewController.swift @@ -15,6 +15,14 @@ class AttendanceCodeDetailViewController: UIViewController { private let descriptionLabel: UILabel = UILabel() private let attendButton: UIButton = UIButton() + private var inputCodeString: String { + var string = "" + self.codeTextFields.forEach { textField in + string.append(textField.text ?? " ") + } + return string + } + // MARK: - Lifecycle override func viewDidLoad() { super.viewDidLoad() @@ -51,7 +59,21 @@ class AttendanceCodeDetailViewController: UIViewController { } private func setupNavigation() { + let navigationBar = self.navigationController?.navigationBar + let appearance = navigationBar?.standardAppearance ?? UINavigationBarAppearance() + appearance.shadowColor = .rgba(24, 24, 24, 0.16) + appearance.backgroundColor = .white.withAlphaComponent(0.96) + navigationBar?.standardAppearance = appearance + let backButtonImage = UIImage(systemName: "arrow.left") + let backBarButton = UIBarButtonItem(image: backButtonImage, style: .plain, target: self, action: #selector(popViewController)) + self.navigationItem.leftBarButtonItem = backBarButton + + let titleLabel = UILabel() + titleLabel.text = "서울특별시 강남구 역삼로" + titleLabel.textColor = .black + titleLabel.font = .systemFont(ofSize: 14) + self.navigationItem.titleView = titleLabel } private func setupViews() { @@ -83,7 +105,8 @@ class AttendanceCodeDetailViewController: UIViewController { self.backgroundView.addSubview(self.descriptionLabel) self.attendButton.setTitle("출석하기", size: 16, weight: .bold, color: .white) - self.attendButton.configurate(bgColor: .rgba(56, 56, 56, 1), cornerRadius: 7, padding: 10) + self.configureAttendButtonEnabled() + self.attendButton.addTarget(self, action: #selector(didTapAttendButton), for: .touchUpInside) } // MARK: - Layout @@ -138,11 +161,39 @@ class AttendanceCodeDetailViewController: UIViewController { make.height.equalTo(54) } } + + // MARK: - Actions + @objc private func didTapAttendButton() { + self.popViewController() + } + + private func configureAttendButtonEnabled() { + let isAttendButtonEnabled = { + for textField in self.codeTextFields where textField.text.isEmptyOrNil { + return false + } + return true + }() + + if isAttendButtonEnabled { + self.attendButton.isEnabled = true + self.attendButton.configurate(bgColor: .rgba(56, 56, 56, 1), cornerRadius: 7, padding: 10) + } else { + self.attendButton.isEnabled = false + self.attendButton.configurate(bgColor: .rgba(200, 200, 200, 1), cornerRadius: 7, padding: 10) + } + } + + @objc private func popViewController(animated: Bool = true) { + self.navigationController?.popViewController(animated: true) + } } // MARK: - UITextFieldDelegate extension AttendanceCodeDetailViewController: UITextFieldDelegate { func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { + defer { self.configureAttendButtonEnabled() } + let currentText = textField.text ?? "" let newText = range.lowerBound == 0 ? string : currentText.replaced(string, in: range) ?? "" @@ -183,7 +234,7 @@ extension AttendanceCodeDetailViewController: UITextFieldDelegate { } // MARK: - TextField Actions - @objc func keyboardWillShow(_ notification: NSNotification) { + @objc private func keyboardWillShow(_ notification: NSNotification) { if self.isEditingCode { self.attendButton.moveWithKeyboard( willShow: true, @@ -193,7 +244,7 @@ extension AttendanceCodeDetailViewController: UITextFieldDelegate { } } - @objc func keyboardWillHide(_ notification: NSNotification) { + @objc private func keyboardWillHide(_ notification: NSNotification) { self.attendButton.moveWithKeyboard( willShow: false, notification: notification, diff --git a/momoIOS/UserSide/Main/MainViewController.swift b/momoIOS/UserSide/Main/MainViewController.swift index 11079a8..2f2ed57 100644 --- a/momoIOS/UserSide/Main/MainViewController.swift +++ b/momoIOS/UserSide/Main/MainViewController.swift @@ -66,7 +66,8 @@ class MainViewController: UIViewController { // MARK: - Action private func goToAttendanceVC() { - self.navigationController?.popViewController(animated: true) + let attendanceCodeDetailVC = AttendanceCodeDetailViewController() + self.navigationController?.pushViewController(attendanceCodeDetailVC, animated: true) } private func showAbsenceModal() {