From 0f52e2cf642af66dcc434cb807cbdc5db87a681a Mon Sep 17 00:00:00 2001 From: LeeMyeongJin Date: Sat, 2 Dec 2023 18:43:04 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[Feat]=20#212=20-=20=EB=93=9C=EB=A1=AD?= =?UTF-8?q?=EB=8B=A4=EC=9A=B4=20=EB=A9=94=EB=89=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 러닝 기록 상세페이지 메뉴를 드롭다운으로 수정 하였습니다. --- .../VC/InfoVC/ActivityRecordDetailVC.swift | 111 ++++++++++++------ 1 file changed, 75 insertions(+), 36 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordDetailVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordDetailVC.swift index 7030b17d..0a93573b 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordDetailVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordDetailVC.swift @@ -10,21 +10,22 @@ import UIKit import SnapKit import Then import Moya +import DropDown final class ActivityRecordDetailVC: UIViewController { // MARK: - Properties private let recordProvider = Providers.recordProvider - + private var recordId: Int? - + private let courseTitleMaxLength = 20 - + // MARK: - UI Components private lazy var navibar = CustomNavigationBar(self, type: .titleWithLeftButton) - + private let moreButton = UIButton(type: .system).then { $0.setImage(ImageLiterals.icMore, for: .normal) $0.tintColor = .g1 @@ -125,25 +126,35 @@ final class ActivityRecordDetailVC: UIViewController { extension ActivityRecordDetailVC { @objc func moreButtonDidTap() { - let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) - let editAction = UIAlertAction(title: "수정하기", style: .default, handler: {(_: UIAlertAction!) in - // 수정 모드일 때 - self.setEditMode() - }) - let deleteAlertVC = RNAlertVC(description: "러닝 기록을 정말로 삭제하시겠어요?").setButtonTitle("취소", "삭제하기") - deleteAlertVC.modalPresentationStyle = .overFullScreen - let deleteAlertAction = UIAlertAction(title: "삭제하기", style: .destructive, handler: {(_: UIAlertAction!) in - self.present(deleteAlertVC, animated: false, completion: nil)}) - deleteAlertVC.rightButtonTapAction = { [weak self] in - deleteAlertVC.dismiss(animated: false) - self?.deleteRecord() + let hideLastCellSeparatorBoxSize = 79 + let items = ["수정하기", "삭제하기"] + let imageArray: [UIImage] = [ImageLiterals.icModify, ImageLiterals.icRemove] + + let menu = DropDown().then { + $0.anchorView = moreButton + $0.backgroundColor = .w1 + $0.bottomOffset = CGPoint(x: -136, y: moreButton.bounds.height - 10) + $0.width = 170 + $0.cellHeight = 40 + $0.cornerRadius = 12 + $0.dismissMode = .onTap + $0.separatorColor = UIColor(hex: "#EBEBEB") + $0.dataSource = items + $0.textFont = .b3 + } + + menu.customCellConfiguration = { (index: Index, _: String, cell: DropDownCell) -> Void in + let lastDividerLineRemove = UIView(frame: CGRect(origin: CGPoint(x: 0, y: hideLastCellSeparatorBoxSize), size: CGSize(width: 170, height: 10))) + lastDividerLineRemove.backgroundColor = .white + cell.separatorInset = .zero + cell.dropDownImage.image = imageArray[index] + cell.addSubview(lastDividerLineRemove) } - let cancelAction = UIAlertAction(title: "닫기", style: .cancel, handler: nil) + dropDownTouchAction(menu: menu) - [ editAction, deleteAlertAction, cancelAction ].forEach { alertController.addAction($0) } - present(alertController, animated: true, completion: nil) + menu.show() } @objc private func textFieldTextDidChange() { @@ -166,30 +177,28 @@ extension ActivityRecordDetailVC { } } - @objc private func keyboardWillShow(_ notification: Notification) { - guard let userInfo = notification.userInfo, - let keyboardFrame = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { - return + @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 } - - let contentInset = UIEdgeInsets( - top: 0.0, - left: 0.0, - bottom: keyboardFrame.size.height, - right: 0.0) - middleScorollView.contentInset = contentInset - middleScorollView.scrollIndicatorInsets = contentInset } - @objc private func keyboardWillHide() { - let contentInset = UIEdgeInsets.zero - middleScorollView.contentInset = contentInset - middleScorollView.scrollIndicatorInsets = contentInset + @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 finishEditButtonDidTap() { editRecordTitle() + // 키보드가 올라와 있을때 내려가는 코드 추가 + view.endEditing(true) + // 수정이 완료되면 팝업 뜨지 않음 self.navibar.resetLeftButtonAction({ [weak self] in self?.navigationController?.popViewController(animated: true) @@ -245,7 +254,6 @@ extension ActivityRecordDetailVC { private func setAddTarget() { self.moreButton.addTarget(self, action: #selector(moreButtonDidTap), for: .touchUpInside) - self.courseTitleTextField.addTarget(self, action: #selector(textFieldTextDidChange), for: .editingChanged) self.finishEditButton.addTarget(self, action: #selector(finishEditButtonDidTap), for: .touchUpInside) } @@ -530,3 +538,34 @@ extension ActivityRecordDetailVC { } } } +// MARK: - DropDown + +extension ActivityRecordDetailVC { + private func dropDownTouchAction(menu: DropDown) { + + DropDown.appearance().textColor = .g1 + DropDown.appearance().selectionBackgroundColor = .w1 + DropDown.appearance().shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.2) + DropDown.appearance().shadowOpacity = 1 + DropDown.appearance().shadowRadius = 10 + + menu.selectionAction = { [unowned self] (_, item) in + menu.clearSelection() + + switch item { + case "수정하기": + self.setEditMode() + case "삭제하기": + let deleteAlertVC = RNAlertVC(description: "러닝 기록을 정말로 삭제하시겠어요?").setButtonTitle("취소", "삭제하기") + deleteAlertVC.modalPresentationStyle = .overFullScreen + deleteAlertVC.rightButtonTapAction = { + deleteAlertVC.dismiss(animated: false) + self.deleteRecord() + } + self.present(deleteAlertVC, animated: false) + default: + self.showToast(message: "없는 명령어 입니다.") + } + } + } +} From 6e4b73232c966e6ee73f4b5b877a64b701183adb Mon Sep 17 00:00:00 2001 From: LeeMyeongJin Date: Sat, 2 Dec 2023 18:43:54 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[Chore]=20#212=20-=20=EC=BD=94=EC=8A=A4=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=ED=95=98=EB=8A=94=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=A5=BC=20=EC=95=BD=EA=B0=84=20=EC=88=98=EC=A0=95=20=ED=95=98?= =?UTF-8?q?=EC=98=80=EC=8A=B5=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VC/InfoVC/ActivityRecordDetailVC.swift | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordDetailVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordDetailVC.swift index 0a93573b..cdc73e14 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordDetailVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordDetailVC.swift @@ -43,15 +43,18 @@ final class ActivityRecordDetailVC: UIViewController { $0.font = .h4 } - private let courseTitleTextField = UITextField().then { - $0.resignFirstResponder() + private lazy var courseTitleTextField = UITextField().then { + let paragraphStyle = NSMutableParagraphStyle() + paragraphStyle.alignment = .center + $0.attributedPlaceholder = NSAttributedString( string: "글 제목", - attributes: [.font: UIFont.h4, .foregroundColor: UIColor.g3] + attributes: [.font: UIFont.h4, .foregroundColor: UIColor.g3, .paragraphStyle: paragraphStyle] ) $0.font = .h4 $0.textColor = .g1 $0.addLeftPadding(width: 2) + $0.addTarget(self, action: #selector(textFieldTextDidChange), for: .editingChanged) } private let recordDateInfoView = CourseDetailInfoView(title: "날짜", description: String()) @@ -71,7 +74,7 @@ final class ActivityRecordDetailVC: UIViewController { private lazy var recordDistanceLabel = SetInfoLayout.makeGreySmailTitleLabel().then { $0.text = "거리" } - + private lazy var recordRunningTimeLabel = SetInfoLayout.makeGreySmailTitleLabel().then { $0.text = "이동 시간" } @@ -79,7 +82,7 @@ final class ActivityRecordDetailVC: UIViewController { private lazy var recordAveragePaceLabel = SetInfoLayout.makeGreySmailTitleLabel().then { $0.text = "평균 페이스" } - + private lazy var recordDistanceValueLabel = SetInfoLayout.makeBlackTitleLabel() private lazy var recordRunningTimeValueLabel = SetInfoLayout.makeBlackTitleLabel() @@ -211,6 +214,7 @@ extension ActivityRecordDetailVC { make.leading.trailing.equalTo(view.safeAreaLayoutGuide) make.bottom.equalTo(view.safeAreaLayoutGuide) } + } @objc private func presentToQuitEditAlertVC() { @@ -315,8 +319,11 @@ extension ActivityRecordDetailVC { extension ActivityRecordDetailVC: UITextFieldDelegate { func textFieldShouldReturn(_ textField: UITextField) -> Bool { + textField.resignFirstResponder() if textField == self.courseTitleTextField { - self.finishEditButtonDidTap() + if finishEditButton.isEnabled == true { + self.finishEditButtonDidTap() + } } return true } @@ -427,7 +434,7 @@ extension ActivityRecordDetailVC { private func setEditMode() { self.navibar.isHidden = false // true - + mapImageView.snp.remakeConstraints { make in make.top.equalToSuperview() make.leading.trailing.equalTo(view.safeAreaLayoutGuide) @@ -439,13 +446,13 @@ extension ActivityRecordDetailVC { self.courseTitleTextField.text = self.courseTitleLabel.text middleScorollView.addSubview(courseTitleTextField) - + courseTitleTextField.snp.makeConstraints { make in make.top.equalTo(mapImageView.snp.bottom).offset(27) make.leading.trailing.equalToSuperview().inset(16) make.height.equalTo(35) } - + self.finishEditButton.isHidden = false firstHorizontalDivideLine.snp.remakeConstraints { make in @@ -469,9 +476,9 @@ extension ActivityRecordDetailVC { make.top.equalTo(secondHorizontalDivideLine.snp.bottom).offset(22) make.centerX.equalToSuperview() } - + middleScorollView.addSubview(finishEditButton) - + finishEditButton.snp.makeConstraints { make in make.bottom.equalToSuperview().inset(30) make.leading.trailing.equalTo(view.safeAreaLayoutGuide).inset(16) @@ -526,6 +533,7 @@ extension ActivityRecordDetailVC { if 200..<300 ~= status { print("제목 수정 성공") self.showToast(message: "제목 수정이 완료되었어요") + self.finishEditButton.isEnabled = false } if status >= 400 { print("400 error") From f12c62fe10be55f4fcafa9dae6b6eb370d079339 Mon Sep 17 00:00:00 2001 From: LeeMyeongJin Date: Sat, 2 Dec 2023 19:03:16 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[Fix]=20#212=20-=20paragraph=20=EC=BD=94?= =?UTF-8?q?=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 --- .../MyPage/VC/InfoVC/ActivityRecordDetailVC.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordDetailVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordDetailVC.swift index cdc73e14..53c9057b 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordDetailVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordDetailVC.swift @@ -44,12 +44,10 @@ final class ActivityRecordDetailVC: UIViewController { } private lazy var courseTitleTextField = UITextField().then { - let paragraphStyle = NSMutableParagraphStyle() - paragraphStyle.alignment = .center $0.attributedPlaceholder = NSAttributedString( string: "글 제목", - attributes: [.font: UIFont.h4, .foregroundColor: UIColor.g3, .paragraphStyle: paragraphStyle] + attributes: [.font: UIFont.h4, .foregroundColor: UIColor.g3] ) $0.font = .h4 $0.textColor = .g1 @@ -199,7 +197,7 @@ extension ActivityRecordDetailVC { @objc private func finishEditButtonDidTap() { editRecordTitle() - // 키보드가 올라와 있을때 내려가는 코드 추가 + // 키보드가 올라와 있다면 내려가는 코드 추가 view.endEditing(true) // 수정이 완료되면 팝업 뜨지 않음