From 5aa93e8d29ebc2c61b07c46539deccccebaca407 Mon Sep 17 00:00:00 2001 From: hyungyu Kim Date: Thu, 2 Dec 2021 13:14:51 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[FEAT]=20#103=20-=20image=20picker=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=20=EB=B0=8F=20=EB=AA=85=ED=95=A8=EB=B0=B0?= =?UTF-8?q?=EA=B2=BD=20=EA=B3=A0=EB=A5=B4=EA=B8=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Descriptions - FrontCardCell 불투명 뷰 추가 - CardInGroupCell 불투명 뷰 추가 - 이미지피커뷰 추가 및 적용 - 배경 선택도 필수로 추가 --- NADA-iOS-forRelease/Info.plist | 19 ---- .../Resouces/Constants/Notification.swift | 2 + .../Cells/CardCell/FrontCardCell.swift | 19 ++++ .../Sources/Cells/CardCell/FrontCardCell.xib | 15 ++- .../BackCardCreationCollectionViewCell.swift | 12 ++- .../BackgroundCollectionViewCell.swift | 13 ++- .../BackgroundCollectionViewCell.xib | 22 ++++- .../FrontCardCreationCollectionViewCell.swift | 96 +++++++++++++------ .../CardInGroupCollectionViewCell.xib | 8 ++ .../CardCreationPreviewViewController.swift | 14 +-- .../CardCreationViewController.swift | 36 ++++++- 11 files changed, 186 insertions(+), 70 deletions(-) diff --git a/NADA-iOS-forRelease/Info.plist b/NADA-iOS-forRelease/Info.plist index 6d12c879..8301cb5a 100644 --- a/NADA-iOS-forRelease/Info.plist +++ b/NADA-iOS-forRelease/Info.plist @@ -10,8 +10,6 @@ Spoqa Han Sans Neo Bold.otf Spoqa Han Sans Neo Regular.otf - LSApplicationCategoryType - NSAppTransportSecurity NSAllowsArbitraryLoads @@ -35,23 +33,8 @@ 1.0 CFBundleVersion 1 - LSApplicationCategoryType - LSRequiresIPhoneOS - NSAppTransportSecurity - - NSAllowsArbitraryLoads - - - UIAppFonts - - NotoSansCJKkr-Bold.otf - NotoSansCJKkr-Medium.otf - NotoSansCJKkr-Regular.otf - Spoqa Han Sans Neo Bold.otf - Spoqa Han Sans Neo Regular.otf - UIApplicationSceneManifest UIApplicationSupportsMultipleScenes @@ -90,7 +73,5 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight - UIUserInterfaceStyle - diff --git a/NADA-iOS-forRelease/Resouces/Constants/Notification.swift b/NADA-iOS-forRelease/Resouces/Constants/Notification.swift index e0fe84a1..059dfc39 100644 --- a/NADA-iOS-forRelease/Resouces/Constants/Notification.swift +++ b/NADA-iOS-forRelease/Resouces/Constants/Notification.swift @@ -14,4 +14,6 @@ extension Notification.Name { // MARK: - Card Creation static let frontCardBirth = Notification.Name("frontCardBirth") static let frontCardMBTI = Notification.Name("frontCardMBTI") + static let presentingImagePicker = Notification.Name("presentingImagePicker") + static let sendNewImage = Notification.Name("sendNewImage") } diff --git a/NADA-iOS-forRelease/Sources/Cells/CardCell/FrontCardCell.swift b/NADA-iOS-forRelease/Sources/Cells/CardCell/FrontCardCell.swift index 5522f8c8..594dc0c6 100644 --- a/NADA-iOS-forRelease/Sources/Cells/CardCell/FrontCardCell.swift +++ b/NADA-iOS-forRelease/Sources/Cells/CardCell/FrontCardCell.swift @@ -73,4 +73,23 @@ extension FrontCardCell { self.instagramIDLabel.text = instagramID self.linkURLLabel.text = linkURL } + + // FIXME: - UIImage 로 넘어올때. 나중에 어떻게 사용할지 정해야함. + func initCell(_ backgroundImage: UIImage?, + _ cardTitle: String, + _ cardDescription: String, + _ userName: String, + _ birth: String, + _ mbti: String, + _ instagramID: String, + _ linkURL: String) { + self.backgroundImageView.image = backgroundImage ?? UIImage() + self.titleLabel.text = cardTitle + self.descriptionLabel.text = cardDescription + self.userNameLabel.text = userName + self.birthLabel.text = birth + self.mbtiLabel.text = mbti + self.instagramIDLabel.text = instagramID + self.linkURLLabel.text = linkURL + } } diff --git a/NADA-iOS-forRelease/Sources/Cells/CardCell/FrontCardCell.xib b/NADA-iOS-forRelease/Sources/Cells/CardCell/FrontCardCell.xib index 5ac3e9e4..3a4d2c8a 100644 --- a/NADA-iOS-forRelease/Sources/Cells/CardCell/FrontCardCell.xib +++ b/NADA-iOS-forRelease/Sources/Cells/CardCell/FrontCardCell.xib @@ -4,7 +4,6 @@ - @@ -25,6 +24,15 @@ + + + + + + + + + + diff --git a/NADA-iOS-forRelease/Sources/Cells/CreationCard/FrontCardCreationCollectionViewCell.swift b/NADA-iOS-forRelease/Sources/Cells/CreationCard/FrontCardCreationCollectionViewCell.swift index 2a82a019..df77d9b7 100644 --- a/NADA-iOS-forRelease/Sources/Cells/CreationCard/FrontCardCreationCollectionViewCell.swift +++ b/NADA-iOS-forRelease/Sources/Cells/CreationCard/FrontCardCreationCollectionViewCell.swift @@ -18,6 +18,9 @@ class FrontCardCreationCollectionViewCell: UICollectionViewCell { private let backgroundList = ["img", "img", "img", "img", "img"] private var requiredTextFieldList = [UITextField]() private var optionalTextFieldList = [UITextField]() + private var cardBackgroundImage: UIImage? + private var defaultImageIndex: Int? + public var presentingBirthBottomVCClosure: (() -> Void)? public var presentingMBTIBottomVCClosure: (() -> Void)? @@ -156,6 +159,32 @@ extension FrontCardCreationCollectionViewCell { private func setNotification() { NotificationCenter.default.addObserver(self, selector: #selector(setBirthTextField(notification:)), name: .frontCardBirth, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(setMBTITextField(notification:)), name: .frontCardMBTI, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(setCardBackgroundImage(notifiation:)), name: .sendNewImage, object: nil) + } + + /// front card 가 편집되었는지. 필수 항목이 다 입력되었는지 체크. + private func checkFrontCradStatus() { + frontCardCreationDelegate?.frontCardCreation(endEditing: true) + if cardTitleTextField.hasText && + userNameTextField.hasText && + birthTextField.hasText && + mbtiTextField.hasText && + defaultImageIndex != nil { + frontCardCreationDelegate?.frontCardCreation(requiredInfo: true) + frontCardCreationDelegate?.frontCardCreation(withRequired: [ + "defaultImageIndex": String(defaultImageIndex ?? -1), + "title": cardTitleTextField.text ?? "", + "name": userNameTextField.text ?? "", + "birthDate": birthTextField.text ?? "", + "mbti": mbtiTextField.text ?? "" + ], withOptional: [ + "instagram": instagramIDTextField.text ?? "", + "linkURL": linkURLTextField.text ?? "", + "description": descriptionTextField.text ?? "" + ]) + } else { + frontCardCreationDelegate?.frontCardCreation(requiredInfo: false) + } } static func nib() -> UINib { return UINib(nibName: Const.Xib.frontCardCreationCollectionViewCell, bundle: Bundle(for: FrontCardCreationCollectionViewCell.self)) @@ -169,17 +198,42 @@ extension FrontCardCreationCollectionViewCell { birthTextField.borderWidth = 0 } - @objc private func setMBTITextField(notification: NSNotification) { mbtiTextField.text = notification.object as? String mbtiTextField.borderWidth = 0 } + @objc + private func setCardBackgroundImage(notifiation: NSNotification) { + cardBackgroundImage = notifiation.object as? UIImage + backgroundSettingCollectionView.reloadData() + } } // MARK: - UICollectionViewDelegate -extension FrontCardCreationCollectionViewCell: UICollectionViewDelegate { } +extension FrontCardCreationCollectionViewCell: UICollectionViewDelegate { + + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + + switch indexPath.item { + case 0: + NotificationCenter.default.post(name: .presentingImagePicker, object: nil) + defaultImageIndex = 0 + case 1: + defaultImageIndex = 1 + case 2: + defaultImageIndex = 2 + case 3: + defaultImageIndex = 3 + case 4: + defaultImageIndex = 4 + default: + return + } + checkFrontCradStatus() + } +} // MARK: - UICollectionViewDataSource extension FrontCardCreationCollectionViewCell: UICollectionViewDataSource { @@ -191,8 +245,14 @@ extension FrontCardCreationCollectionViewCell: UICollectionViewDataSource { guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: Const.Xib.backgroundCollectionViewCell, for: indexPath) as? BackgroundCollectionViewCell else { return UICollectionViewCell() } - cell.initCell(image: backgroundList[indexPath.item]) - + switch indexPath.item { + case 0: + cell.initCell(image: cardBackgroundImage ?? UIImage(), isFirst: true) + default: + // FIXME: - 기본 명함 배경 넘겨주면 수정. +// guard let image = UIImage(systemName: backgroundList[indexPath.item]) else { return UICollectionViewCell() } + cell.initCell(image: UIImage(), isFirst: false) + } return cell } } @@ -216,38 +276,20 @@ extension FrontCardCreationCollectionViewCell: UICollectionViewDelegateFlowLayou // MARK: - UITextFieldDelegate extension FrontCardCreationCollectionViewCell: UITextFieldDelegate { func textFieldDidBeginEditing(_ textField: UITextField) { - if textField == birthTextField { + switch textField { + case birthTextField: textField.endEditing(true) presentingBirthBottomVCClosure?() - } else if textField == mbtiTextField { + case mbtiTextField: textField.endEditing(true) presentingMBTIBottomVCClosure?() - } else { + default: textField.borderWidth = 1 textField.borderColor = .tertiary } } func textFieldDidEndEditing(_ textField: UITextField) { - frontCardCreationDelegate?.frontCardCreation(endEditing: true) - if cardTitleTextField.hasText && - userNameTextField.hasText && - birthTextField.hasText && - mbtiTextField.hasText { - frontCardCreationDelegate?.frontCardCreation(requiredInfo: true) - frontCardCreationDelegate?.frontCardCreation(withRequired: [ - "defaultImage": String(0), - "title": cardTitleTextField.text ?? "", - "name": userNameTextField.text ?? "", - "birthDate": birthTextField.text ?? "", - "mbti": mbtiTextField.text ?? "" - ], withOptional: [ - "instagram": instagramIDTextField.text ?? "", - "linkURL": linkURLTextField.text ?? "", - "description": descriptionTextField.text ?? "" - ]) - } else { - frontCardCreationDelegate?.frontCardCreation(requiredInfo: false) - } + checkFrontCradStatus() textField.resignFirstResponder() textField.borderWidth = 0 } diff --git a/NADA-iOS-forRelease/Sources/Cells/GroupCell/CardInGroupCollectionViewCell.xib b/NADA-iOS-forRelease/Sources/Cells/GroupCell/CardInGroupCollectionViewCell.xib index e2f72212..8f68f63a 100644 --- a/NADA-iOS-forRelease/Sources/Cells/GroupCell/CardInGroupCollectionViewCell.xib +++ b/NADA-iOS-forRelease/Sources/Cells/GroupCell/CardInGroupCollectionViewCell.xib @@ -32,6 +32,10 @@ + + + +