From a81a9e7d50ec7f6c9aa51d0af547062e38a6848f Mon Sep 17 00:00:00 2001 From: woongaaaa Date: Tue, 30 Jul 2024 21:42:31 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EB=B7=B0=20?= =?UTF-8?q?=EC=BD=9C=EB=A0=89=EC=85=98=20=EB=B7=B0=EB=A1=9C=20=EA=B5=AC?= =?UTF-8?q?=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MEME/MEME.xcodeproj/project.pbxproj | 4 + ...ArtistPortfolioEditingViewController.swift | 334 ++++-------------- .../ArtistPortfolioEditingViewController.xib | 176 ++------- .../PortfolioImageCollectionViewCell.swift | 48 +++ 4 files changed, 165 insertions(+), 397 deletions(-) create mode 100644 MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift diff --git a/MEME/MEME.xcodeproj/project.pbxproj b/MEME/MEME.xcodeproj/project.pbxproj index 791abd1..c78cac7 100644 --- a/MEME/MEME.xcodeproj/project.pbxproj +++ b/MEME/MEME.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ 09275E822B518D150033EF34 /* ArtistHomeViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 09275E812B518D150033EF34 /* ArtistHomeViewController.xib */; }; 09275E892B528A610033EF34 /* ArtistReservationStatusTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09275E872B528A610033EF34 /* ArtistReservationStatusTableViewCell.swift */; }; 09275E8A2B528A610033EF34 /* ArtistReservationStatusTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 09275E882B528A610033EF34 /* ArtistReservationStatusTableViewCell.xib */; }; + 0936EDDA2C57FAD300212AF0 /* PortfolioImageCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0936EDD92C57FAD300212AF0 /* PortfolioImageCollectionViewCell.swift */; }; 094884C72B584B7000C233E0 /* ArtistMakeupTagCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 094884C52B584B7000C233E0 /* ArtistMakeupTagCollectionViewCell.swift */; }; 094884C82B584B7000C233E0 /* ArtistMakeupTagCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 094884C62B584B7000C233E0 /* ArtistMakeupTagCollectionViewCell.xib */; }; 094884CB2B584B8F00C233E0 /* ArtistPortfolioCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 094884C92B584B8F00C233E0 /* ArtistPortfolioCollectionViewCell.swift */; }; @@ -349,6 +350,7 @@ 09275E812B518D150033EF34 /* ArtistHomeViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ArtistHomeViewController.xib; sourceTree = ""; }; 09275E872B528A610033EF34 /* ArtistReservationStatusTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArtistReservationStatusTableViewCell.swift; sourceTree = ""; }; 09275E882B528A610033EF34 /* ArtistReservationStatusTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ArtistReservationStatusTableViewCell.xib; sourceTree = ""; }; + 0936EDD92C57FAD300212AF0 /* PortfolioImageCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PortfolioImageCollectionViewCell.swift; sourceTree = ""; }; 094884C52B584B7000C233E0 /* ArtistMakeupTagCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArtistMakeupTagCollectionViewCell.swift; sourceTree = ""; }; 094884C62B584B7000C233E0 /* ArtistMakeupTagCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ArtistMakeupTagCollectionViewCell.xib; sourceTree = ""; }; 094884C92B584B8F00C233E0 /* ArtistPortfolioCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArtistPortfolioCollectionViewCell.swift; sourceTree = ""; }; @@ -776,6 +778,7 @@ isa = PBXGroup; children = ( 0957424F2B66153E0011B580 /* ArtistPortfolioEditingViewController.swift */, + 0936EDD92C57FAD300212AF0 /* PortfolioImageCollectionViewCell.swift */, 095742502B66153E0011B580 /* ArtistPortfolioEditingViewController.xib */, ); path = ArtistPortfolioEditingView; @@ -2411,6 +2414,7 @@ 31EA86F42BBFEC39003BCBF7 /* MoyaAsyncError.swift in Sources */, CC2F3AC22B54361100508DA5 /* MyPageInfoViewController.swift in Sources */, 2DA2080B2B7AFC36006EB9B9 /* ModelSearchResultViewController.swift in Sources */, + 0936EDDA2C57FAD300212AF0 /* PortfolioImageCollectionViewCell.swift in Sources */, 316239672B80DE9B002D9E2F /* BasicResponseDTO.swift in Sources */, 31B4137E2B6D29C500535BB1 /* BusinessIDVerificationAPI.swift in Sources */, 31F6F8482B52C7B800EC621D /* NavigationBarView.swift in Sources */, diff --git a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.swift b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.swift index f07b247..5f38c90 100644 --- a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.swift +++ b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.swift @@ -7,19 +7,10 @@ import UIKit -class ArtistPortfolioEditingViewController: UIViewController, UINavigationControllerDelegate { +class ArtistPortfolioEditingViewController: UIViewController { //MARK: - UI Properties + @IBOutlet private weak var portfolioImageCollectionView: UICollectionView! @IBOutlet private weak var makeupCategoryCollectionView: UICollectionView! - @IBOutlet private weak var imagePickerStackView: UIStackView! - - @IBOutlet private weak var firstImgView: UIImageView! - @IBOutlet private weak var secondImgView: UIImageView! - @IBOutlet private weak var thirdImgView: UIImageView! - - @IBOutlet private weak var firstDeleteButton: UIButton! - @IBOutlet private weak var secondDeleteButton: UIButton! - @IBOutlet private weak var thirdDeleteButton: UIButton! - @IBOutlet private weak var makeupNameTextField: UITextField! @IBOutlet private weak var priceTextField: UITextField! @IBOutlet private weak var infoTextView: UITextView! @@ -52,19 +43,10 @@ class ArtistPortfolioEditingViewController: UIViewController, UINavigationContro private var isBlock : Bool = false private var selectedCategory: PortfolioCategories? - private var buttonAt: Int = 0 - private var imgCnt: Int = 0 - private var isEdit: Bool = portfolioIdx == -1 ? false : true - private lazy var imgViewUrlList: [String] = [] - private var portfolioImageData: [ImageData]? - private lazy var imgViewList: [UIImageView] = { - return [self.firstImgView, self.secondImgView, self.thirdImgView] - }() - //MARK: - ViewController 생명 주기 override func viewDidLoad() { super.viewDidLoad() - if isEdit { + if portfolioId == -1 { getPortfolioDetail() } configureSubviews() @@ -83,19 +65,9 @@ class ArtistPortfolioEditingViewController: UIViewController, UINavigationContro infoTextView.layer.cornerRadius = 10 infoTextView.layer.borderWidth = 1 infoTextView.layer.borderColor = UIColor.gray200.cgColor - firstImgView.layer.cornerRadius = 5 - secondImgView.layer.cornerRadius = 5 - thirdImgView.layer.cornerRadius = 5 - - - [firstDeleteButton, secondDeleteButton, thirdDeleteButton].forEach { button in - button?.layer.cornerRadius = 5 - button?.layer.maskedCorners = .layerMaxXMinYCorner - button?.layer.masksToBounds = true - } priceTextField.keyboardType = .numberPad - if !isEdit { + if portfolioId == -1 { artistProfileEditingInfoBar.setTitle("수정하기", for: .normal) self.navigationItem.title = "포트폴리오 수정" navigationItem.rightBarButtonItem = UIBarButtonItem(image: .icTrash.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(trashButtonDidTap)) @@ -103,7 +75,6 @@ class ArtistPortfolioEditingViewController: UIViewController, UINavigationContro self.navigationItem.title = "포트폴리오 추가" artistProfileEditingInfoBar.setTitle("추가하기", for: .normal) } - deleteButtonAppear() } //MARK: - collectionViewConfigure() @@ -111,7 +82,9 @@ class ArtistPortfolioEditingViewController: UIViewController, UINavigationContro makeupCategoryCollectionView.delegate = self makeupCategoryCollectionView.dataSource = self makeupCategoryCollectionView.register(UINib(nibName: ArtistMakeupTagCollectionViewCell.className, bundle: nil), forCellWithReuseIdentifier: ArtistMakeupTagCollectionViewCell.className) - + portfolioImageCollectionView.delegate = self + portfolioImageCollectionView.dataSource = self + portfolioImageCollectionView.register(PortfolioImageCollectionViewCell.self, forCellWithReuseIdentifier: PortfolioImageCollectionViewCell.className) } //MARK: - codebase UI config @@ -129,26 +102,6 @@ class ArtistPortfolioEditingViewController: UIViewController, UINavigationContro } } - //MARK: - deleteButtonAppear() - private func deleteButtonAppear() { - if self.imgCnt==3 { - firstDeleteButton.isHidden = false - secondDeleteButton.isHidden = false - thirdDeleteButton.isHidden = false - }else if self.imgCnt==2 { - firstDeleteButton.isHidden = true - secondDeleteButton.isHidden = false - thirdDeleteButton.isHidden = false - }else if self.imgCnt==1 { - firstDeleteButton.isHidden = true - secondDeleteButton.isHidden = false - thirdDeleteButton.isHidden = true - }else { - firstDeleteButton.isHidden = true - secondDeleteButton.isHidden = true - thirdDeleteButton.isHidden = true - } - } //MARK: - @IBAction @IBAction func backButtonDidTap(_ sender: UIButton) { let okAction = UIAlertAction(title: "예", style: .default) { [weak self] _ in @@ -159,7 +112,7 @@ class ArtistPortfolioEditingViewController: UIViewController, UINavigationContro var title = "" var message = "" - if isEdit { + if portfolioId == -1 { title = "포트폴리오 수정하기" message = "\n포트폴리오 수정을 취소하시겠습니까?" } else { @@ -181,50 +134,39 @@ class ArtistPortfolioEditingViewController: UIViewController, UINavigationContro } @objc func editButtonDidTap(_ sender: UIButton) { - let okCreateAction = UIAlertAction(title: "예", style: .default) { [weak self] _ in - self?.createPortfolio(completion: { result in - self?.navigationController?.popViewController(animated: true) - }) - } - let okEditAction = UIAlertAction(title: "예", style: .default) { [weak self] _ in - self?.editPortfolio(completion: { result in - self?.navigationController?.popViewController(animated: true) - }) - } - - let noAction = UIAlertAction(title: "아니오", style: .cancel, handler: nil) - + let okAction: UIAlertAction var title = "" var message = "" - if isEdit { + if portfolioId == -1 { title = "포트폴리오 수정하기" message = "\n포트폴리오를 수정하시겠습니까?" + okAction = UIAlertAction(title: "예", style: .default) { [weak self] _ in + // TODO: 포트폴리오 수정 + } } else { title = "포트폴리오 등록하기" message = "\n포트폴리오를 등록하시겠습니까?" + okAction = UIAlertAction(title: "예", style: .default) { [weak self] _ in + // TODO: 포트폴리오 생성 + } } - let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) + let noAction = UIAlertAction(title: "아니오", style: .cancel, handler: nil) - // HIG에 따라 Cancel이 왼쪽 - if isEdit{ - alert.addAction(okEditAction) - }else { - alert.addAction(okCreateAction) - } + let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) + alert.addAction(okAction) alert.addAction(noAction) present(alert, animated: true, completion: nil) } + @IBAction func trashButtonDidTap(_ sender: UIButton) { let alert = UIAlertController(title: "포트폴리오 삭제하기", message: "\n포트폴리오를 삭제하시겠습니까?", preferredStyle: .alert) let okAction = UIAlertAction(title: "예", style: .default) { [weak self] _ in self?.isBlock=true - self?.editPortfolio(completion: { result in - self?.navigationController?.popViewController(animated: true) - }) + // TODO: 포트폴리오 삭제 } let noAction = UIAlertAction( title: "아니오", @@ -236,87 +178,65 @@ class ArtistPortfolioEditingViewController: UIViewController, UINavigationContro alert.addAction(noAction) present(alert, animated: true, completion: nil) } - @IBAction func pick(_ sender: UIButton) { - // 이미지 피커 컨트롤러 생성 - buttonAt = sender.tag - let picker = UIImagePickerController() - picker.sourceType = .photoLibrary // 이미지 소스로 사진 라이브러리 선택 - picker.allowsEditing = true // 이미지 편집 기능 On - // 델리게이트 지정 - picker.delegate = self - - // 이미지 피커 컨트롤러 실행 - self.present(picker, animated: false) - } - @IBAction func deleteImg(_ sender: UIButton) { - buttonAt = sender.tag - if buttonAt==0 { - imgViewList[0].image = .icPicture - }else if buttonAt==1 { - if imgCnt==1 { - imgViewList[buttonAt].image = nil - imgViewList[0].image = .icPicture - imgViewUrlList[0] = "string" - }else if imgCnt==2 { - imgViewList[buttonAt].image = imgViewList[buttonAt+1].image - imgViewList[buttonAt+1].image = nil - imgViewList[0].image = .icPicture - }else { - imgViewList[buttonAt].image = imgViewList[buttonAt-1].image - imgViewList[0].image = .icPicture - } - }else{ - if imgCnt==3 { - imgViewList[buttonAt].image = imgViewList[buttonAt-1].image - imgViewList[buttonAt-1].image = imgViewList[buttonAt-2].image - imgViewList[0].image = .icPicture - }else { - imgViewList[buttonAt].image = nil - } - } - imgCnt-=1 - deleteButtonAppear() - } - } //MARK: - UICollectionViewDataSource extension ArtistPortfolioEditingViewController : UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return portfolioCategories.count + if collectionView == makeupCategoryCollectionView{ + return portfolioCategories.count + }else { + return 4 + } } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ArtistMakeupTagCollectionViewCell.className, for: indexPath) as? ArtistMakeupTagCollectionViewCell else { return UICollectionViewCell() } - let tagName = portfolioCategories[indexPath.row].korName - cell.makeupTagLabel.text = tagName - - if let selectedCategory = selectedCategory { - if selectedCategory == portfolioCategories[indexPath.row] { - cell.selected() + if collectionView == makeupCategoryCollectionView { + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ArtistMakeupTagCollectionViewCell.className, for: indexPath) as? ArtistMakeupTagCollectionViewCell else { return UICollectionViewCell() } + let tagName = portfolioCategories[indexPath.row].korName + cell.makeupTagLabel.text = tagName + + if let selectedCategory = selectedCategory { + if selectedCategory == portfolioCategories[indexPath.row] { + cell.selected() + } else { + } } else { } - } else { + return cell + }else { + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PortfolioImageCollectionViewCell.className, for: indexPath) as? PortfolioImageCollectionViewCell else { return UICollectionViewCell() } + // 이미지 설정 + cell.delegate = self + return cell } - return cell } } //MARK: - UICollectionViewDelegate extension ArtistPortfolioEditingViewController : UICollectionViewDelegate { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - // 선택된 indexPath에 대한 셀을 가져오기 - if let selectedCell = collectionView.cellForItem(at: indexPath) as? ArtistMakeupTagCollectionViewCell { - // 선택된 셀에 대한 작업 수행 - selectedCell.selected() - selectedCategory = portfolioCategories[indexPath.row] - } - - // 나머지 indexPath에 대한 셀을 가져와서 작업 수행 - for visibleIndexPath in collectionView.indexPathsForVisibleItems { - if visibleIndexPath != indexPath, - let deselectedCell = collectionView.cellForItem(at: visibleIndexPath) as? ArtistMakeupTagCollectionViewCell { - // 선택되지 않은 셀에 대한 작업 수행 - deselectedCell.deSelected() + if collectionView == makeupCategoryCollectionView { + // 선택된 indexPath에 대한 셀을 가져오기 + if let selectedCell = collectionView.cellForItem(at: indexPath) as? ArtistMakeupTagCollectionViewCell { + // 선택된 셀에 대한 작업 수행 + selectedCell.selected() + selectedCategory = portfolioCategories[indexPath.row] + } + + // 나머지 indexPath에 대한 셀을 가져와서 작업 수행 + for visibleIndexPath in collectionView.indexPathsForVisibleItems { + if visibleIndexPath != indexPath, + let deselectedCell = collectionView.cellForItem(at: visibleIndexPath) as? ArtistMakeupTagCollectionViewCell { + // 선택되지 않은 셀에 대한 작업 수행 + deselectedCell.deSelected() + } + } + } else { + //TODO: 이미지 변경 혹은 추가 + if indexPath.row == 0 { + + }else { + } } } @@ -329,6 +249,7 @@ extension ArtistPortfolioEditingViewController: UICollectionViewDelegateFlowLayo layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath ) -> CGSize { + if collectionView == makeupCategoryCollectionView { var width = 97 switch indexPath.row { case 3: @@ -341,6 +262,9 @@ extension ArtistPortfolioEditingViewController: UICollectionViewDelegateFlowLayo break } return CGSize(width: width, height: 27) + }else { + return CGSize(width: collectionView.bounds.height, height: collectionView.bounds.height) + } } func collectionView( _ collectionView: UICollectionView, @@ -358,127 +282,18 @@ extension ArtistPortfolioEditingViewController: UICollectionViewDelegateFlowLayo } } -// MARK: - UIImagePickerControllerDelegate -extension ArtistPortfolioEditingViewController : UIImagePickerControllerDelegate{ - func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { - // 이미지 피커 컨트롤러 창 닫기 - self.dismiss(animated: false) { () in - // 알림 창 호출 - let alert = UIAlertController( - title: "", - message: "이미지 선택이 취소되었습니다.", - preferredStyle: .alert - ) - alert.addAction(UIAlertAction( - title: "확인", - style: .cancel - )) - self.present(alert, animated: false) - } - } - // 이미지 피커에서 이미지를 선택했을 때 호출되는 메소드 - func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { - // 이미지 피커 컨트롤러 창 닫기 - picker.dismiss(animated: false) { () in - let img = info[UIImagePickerController.InfoKey.editedImage] as? UIImage - self.imgViewList[1].image = img - self.imgCnt += 1 - self.deleteButtonAppear() - - } - } -} - //MARK: - API 호출 extension ArtistPortfolioEditingViewController { private func getPortfolioDetail() { - let getPortfolio = PortfolioManager.shared - self.infoTextViewPlaceHolderLabel.isHidden = true - getPortfolio.getPortfolioDetail(userId: modelID, portfolioId: portfolioId) { result in - switch result { - case .success(let response): - if let url = URL(string: response.data!.portfolioImgDtoList![0].portfolioImgSrc) { - URLSession.shared.dataTask( - with: url) { - data, response, error in - DispatchQueue.main.async { - if let data = data, error == nil { - self.imgCnt = 1 - self.deleteButtonAppear() - self.secondImgView.image = UIImage(data: data) - } else { - self.secondImgView.image = nil - } - } - }.resume() - self.portfolioImageData = response.data?.portfolioImgDtoList - } else { - self.firstImgView.image = nil - } - self.portfolioDetailData = response.data - self.selectedCategory = PortfolioCategories(rawValue: response.data!.category) - self.makeupCategoryCollectionView.reloadData() - self.makeupNameTextField.text = response.data?.makeupName - self.priceTextField.text = String(response.data!.price) - self.infoTextView.text = response.data?.info - case .failure(let error): - print(error) - } - } + } - private func createPortfolio(completion: @escaping (Bool) -> Void) { - let createPortfolio = PortfolioManager.shared - createPortfolio.createPortfolio( - artistId: artistID, - category: selectedCategory!, - makeup_name: makeupNameTextField.text!, - price: Int(priceTextField.text!)!, - info: infoTextView.text!, - portfolio_img_src: imgViewUrlList - ) { result in - switch result { - case .success(let data): - print(data.message) - completion(true) - case .failure(let error): - print(error.localizedDescription) - completion(false) - } - } + private func createPortfolio(){ + } - private func editPortfolio(completion: @escaping (Bool) -> Void) { - FirebaseStorageManager.uploadImage(image: imgViewList[0].image!) { [self] url in - guard - let url = url, - let aritstId = KeyChainManager.read(forkey: .memberId) as? Int - else { return } // 성공적으로 업로드 했으면 url이 nil 값이 아님 - portfolioImageData?[0].portfolioImgSrc = url.absoluteString - portfolioImageData?[0].delete = false - let editPortfolio = PortfolioManager.shared - editPortfolio.editPortfolio( - artistId: aritstId, - portfolioId: portfolioId, - category: selectedCategory!, - makeup_name: makeupNameTextField.text!, - price: Int(priceTextField.text!)!, - info: infoTextView.text, - isBlock: isBlock, - portfolio_img_src: portfolioImageData! - ) { result in - switch result { - case .success(let response): - print("성공" + response.message) - completion(true) - case .failure(let error): - print("수정 실패" + error.localizedDescription) - completion(false) - } - } - } + private func editPortfolio() { } - } // MARK: - keyboard tabGesture @@ -505,3 +320,8 @@ extension ArtistPortfolioEditingViewController: UITextViewDelegate { } } +extension ArtistPortfolioEditingViewController: PortfolioImageCollectionViewCellDelegate { + func deleteButtonTapped() { + //TODO: 삭제 후 콜렉션 뷰 새로고침 + } +} diff --git a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.xib b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.xib index ba48146..a4fe02d 100644 --- a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.xib +++ b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.xib @@ -17,18 +17,12 @@ - - - + - - - - @@ -50,71 +44,51 @@ - + + + + - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -126,91 +100,8 @@ - - - - - - - - - - - - + @@ -220,50 +111,54 @@ + + + + + + + + + + + + + - - - + - - - - - + - + - - - - + @@ -292,13 +187,14 @@ - - + + + diff --git a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift new file mode 100644 index 0000000..2027acc --- /dev/null +++ b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift @@ -0,0 +1,48 @@ +// +// PortfolioImageCollectionViewCell.swift +// MEME +// +// Created by 황채웅 on 7/30/24. +// + +import UIKit + +protocol PortfolioImageCollectionViewCellDelegate: ArtistPortfolioEditingViewController{ + func deleteButtonTapped() +} + +class PortfolioImageCollectionViewCell: UICollectionViewCell { + private var deleteButton: UIButton{ + let button = UIButton() + button.addTarget(self, action: #selector(deleteButtonTapped), for: .touchUpInside) + return button + } + private var portfolioImageView: UIImageView{ + let imageView = UIImageView() + return imageView + } + weak var delegate: PortfolioImageCollectionViewCellDelegate? + + override init(frame: CGRect) { + super.init(frame: frame) + addSubview(deleteButton) + addSubview(portfolioImageView) + + portfolioImageView.snp.makeConstraints { make in + make.leading.trailing.top.bottom.equalToSuperview() + } + deleteButton.snp.makeConstraints { make in + make.trailing.top.equalToSuperview() + make.height.width.equalTo(18) + } + contentView.layer.cornerRadius = 10 + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + @objc func deleteButtonTapped(_ sender: UIButton){ + delegate?.deleteButtonTapped() + } +} From bfd8bdf7340c222739b92aa2d0d747b6ca893f99 Mon Sep 17 00:00:00 2001 From: woongaaaa Date: Thu, 1 Aug 2024 17:41:37 +0900 Subject: [PATCH 2/4] =?UTF-8?q?PHPickerViewController=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ArtistPortfolioEditingViewController.swift | 49 +++++++++++++++++-- .../PortfolioImageCollectionViewCell.swift | 4 ++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.swift b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.swift index 5f38c90..5645660 100644 --- a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.swift +++ b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.swift @@ -6,6 +6,7 @@ // import UIKit +import PhotosUI class ArtistPortfolioEditingViewController: UIViewController { //MARK: - UI Properties @@ -42,6 +43,9 @@ class ArtistPortfolioEditingViewController: UIViewController { private var portfolioDetailData: PortfolioData! private var isBlock : Bool = false private var selectedCategory: PortfolioCategories? + private var portfolioImage: [UIImage] = [] + private var configuration = PHPickerConfiguration() + private var imageCount: Int = 0 //MARK: - ViewController 생명 주기 override func viewDidLoad() { @@ -54,6 +58,7 @@ class ArtistPortfolioEditingViewController: UIViewController { collectionViewConfigure() setUI() setupDismissKeyboardOnTapGesture() + imagePickerConfigure() } //MARK: - setUI() @@ -102,6 +107,11 @@ class ArtistPortfolioEditingViewController: UIViewController { } } + private func imagePickerConfigure(){ + configuration.selectionLimit = 1 + configuration.filter = .images + } + //MARK: - @IBAction @IBAction func backButtonDidTap(_ sender: UIButton) { let okAction = UIAlertAction(title: "예", style: .default) { [weak self] _ in @@ -186,7 +196,7 @@ extension ArtistPortfolioEditingViewController : UICollectionViewDataSource { if collectionView == makeupCategoryCollectionView{ return portfolioCategories.count }else { - return 4 + return imageCount == 3 ? 3 : imageCount + 1 } } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { @@ -205,7 +215,14 @@ extension ArtistPortfolioEditingViewController : UICollectionViewDataSource { return cell }else { guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PortfolioImageCollectionViewCell.className, for: indexPath) as? PortfolioImageCollectionViewCell else { return UICollectionViewCell() } - // 이미지 설정 + // 이미지 3개 미만일 경우 첫 셀은 기본 이미지 + if imageCount == 3 { + cell.configure(image: portfolioImage[imageCount-1 - indexPath.row]) + }else { + if indexPath.row != 0 { + cell.configure(image: portfolioImage[imageCount - indexPath.row]) + } + } cell.delegate = self return cell } @@ -233,11 +250,18 @@ extension ArtistPortfolioEditingViewController : UICollectionViewDelegate { } } else { //TODO: 이미지 변경 혹은 추가 - if indexPath.row == 0 { + let picker = PHPickerViewController(configuration: configuration) + picker.delegate = self + self.present(picker, animated: true, completion: nil) + if indexPath.row == 0 && portfolioImage.count < 3 { + // 추가 후 데이터 리로드 }else { + // 변경 } + imageCount += 1 + portfolioImageCollectionView.reloadData() } } } @@ -325,3 +349,22 @@ extension ArtistPortfolioEditingViewController: PortfolioImageCollectionViewCell //TODO: 삭제 후 콜렉션 뷰 새로고침 } } + +extension ArtistPortfolioEditingViewController: PHPickerViewControllerDelegate { + + func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) { + picker.dismiss(animated: true, completion: nil) + let itemProvider = results.first?.itemProvider + if let itemProvider = itemProvider, + itemProvider.canLoadObject(ofClass: UIImage.self) { + itemProvider.loadObject(ofClass: UIImage.self) { image, error in + DispatchQueue.main.async { + guard let selectedImage = image as? UIImage else { return } + // TODO: 선택 indexPath.row에 따라 변경 필요 + self.portfolioImage.append(selectedImage) + self.portfolioImageCollectionView.reloadData() + } + } + } + } +} diff --git a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift index 2027acc..74de667 100644 --- a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift +++ b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift @@ -45,4 +45,8 @@ class PortfolioImageCollectionViewCell: UICollectionViewCell { @objc func deleteButtonTapped(_ sender: UIButton){ delegate?.deleteButtonTapped() } + + func configure(image: UIImage){ + portfolioImageView.image = image + } } From 263999df174477216cc5089837b6892210a15418 Mon Sep 17 00:00:00 2001 From: woongaaaa Date: Fri, 2 Aug 2024 18:10:59 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=ED=8F=AC=ED=8A=B8=ED=8F=B4=EB=A6=AC?= =?UTF-8?q?=EC=98=A4=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=B6=94=EA=B0=80/?= =?UTF-8?q?=EC=88=98=EC=A0=95/=EC=82=AD=EC=A0=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ArtistPortfolioEditingViewController.swift | 245 ++++++++---------- .../ArtistPortfolioEditingViewController.xib | 22 +- .../PortfolioImageCollectionViewCell.swift | 44 ++-- .../portfolio_image.imageset/Contents.json | 12 + .../portfolio_image.svg | 6 + 5 files changed, 164 insertions(+), 165 deletions(-) create mode 100644 MEME/MEME/Assets.xcassets/ArtistHome/portfolio_image.imageset/Contents.json create mode 100644 MEME/MEME/Assets.xcassets/ArtistHome/portfolio_image.imageset/portfolio_image.svg diff --git a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.swift b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.swift index 5645660..175d079 100644 --- a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.swift +++ b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.swift @@ -9,7 +9,8 @@ import UIKit import PhotosUI class ArtistPortfolioEditingViewController: UIViewController { - //MARK: - UI Properties + + // MARK: - UI Properties @IBOutlet private weak var portfolioImageCollectionView: UICollectionView! @IBOutlet private weak var makeupCategoryCollectionView: UICollectionView! @IBOutlet private weak var makeupNameTextField: UITextField! @@ -29,25 +30,27 @@ class ArtistPortfolioEditingViewController: UIViewController { return button }() - //MARK: - init + // MARK: - Properties + let portfolioId: Int + private var portfolioDetailData: PortfolioData! + private var isBlock = false + private var selectedCategory: PortfolioCategories? + private var portfolioImage = [UIImage(), UIImage(), UIImage()] + private var configuration = PHPickerConfiguration() + private var imageCount = 0 + private var selectedImageIndexPath = 0 + + // MARK: - Initialization init(receivedData: Int) { self.portfolioId = receivedData super.init(nibName: nil, bundle: nil) } + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } - //MARK: - Properties - let portfolioId: Int - private var portfolioDetailData: PortfolioData! - private var isBlock : Bool = false - private var selectedCategory: PortfolioCategories? - private var portfolioImage: [UIImage] = [] - private var configuration = PHPickerConfiguration() - private var imageCount: Int = 0 - - //MARK: - ViewController 생명 주기 + // MARK: - View Lifecycle override func viewDidLoad() { super.viewDidLoad() if portfolioId == -1 { @@ -61,8 +64,8 @@ class ArtistPortfolioEditingViewController: UIViewController { imagePickerConfigure() } - //MARK: - setUI() - private func setUI(){ + // MARK: - UI Setup + private func setUI() { makeupCategoryCollectionView.backgroundColor = .white infoTextView.backgroundColor = .white self.tabBarController?.tabBar.isHidden = true @@ -72,201 +75,152 @@ class ArtistPortfolioEditingViewController: UIViewController { infoTextView.layer.borderColor = UIColor.gray200.cgColor priceTextField.keyboardType = .numberPad - if portfolioId == -1 { + + if portfolioId != -1 { artistProfileEditingInfoBar.setTitle("수정하기", for: .normal) self.navigationItem.title = "포트폴리오 수정" navigationItem.rightBarButtonItem = UIBarButtonItem(image: .icTrash.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(trashButtonDidTap)) - }else { - self.navigationItem.title = "포트폴리오 추가" + } else { + self.navigationItem.title = "포트폴리오 추가" artistProfileEditingInfoBar.setTitle("추가하기", for: .normal) } } - //MARK: - collectionViewConfigure() - private func collectionViewConfigure(){ + // MARK: - CollectionView Configuration + private func collectionViewConfigure() { makeupCategoryCollectionView.delegate = self makeupCategoryCollectionView.dataSource = self makeupCategoryCollectionView.register(UINib(nibName: ArtistMakeupTagCollectionViewCell.className, bundle: nil), forCellWithReuseIdentifier: ArtistMakeupTagCollectionViewCell.className) + portfolioImageCollectionView.delegate = self portfolioImageCollectionView.dataSource = self portfolioImageCollectionView.register(PortfolioImageCollectionViewCell.self, forCellWithReuseIdentifier: PortfolioImageCollectionViewCell.className) } - //MARK: - codebase UI config + // MARK: - UI Configuration private func configureSubviews() { view.addSubview(artistProfileEditingInfoBar) } - //MARK: - codebase UI constraints private func makeConstraints() { - artistProfileEditingInfoBar.snp.makeConstraints {make in - make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom).offset(0) + artistProfileEditingInfoBar.snp.makeConstraints { make in + make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom) make.leading.equalTo(view.snp.leading).offset(24) make.trailing.equalTo(view.snp.trailing).offset(-24) make.height.equalTo(49) } } - private func imagePickerConfigure(){ + private func imagePickerConfigure() { configuration.selectionLimit = 1 configuration.filter = .images } - //MARK: - @IBAction + // MARK: - Actions @IBAction func backButtonDidTap(_ sender: UIButton) { let okAction = UIAlertAction(title: "예", style: .default) { [weak self] _ in self?.navigationController?.popViewController(animated: true) } - let noAction = UIAlertAction(title: "아니오", style: .cancel, handler: nil) - - var title = "" - var message = "" - - if portfolioId == -1 { - title = "포트폴리오 수정하기" - message = "\n포트폴리오 수정을 취소하시겠습니까?" - } else { - title = "포트폴리오 등록하기" - message = "\n포트폴리오 등록을 취소하시겠습니까?" - } + let noAction = UIAlertAction(title: "아니오", style: .cancel) - let alert = UIAlertController( - title: title, - message: message, - preferredStyle: .alert - ) + let title = portfolioId == -1 ? "포트폴리오 수정하기" : "포트폴리오 등록하기" + let message = portfolioId == -1 ? "\n포트폴리오 수정을 취소하시겠습니까?" : "\n포트폴리오 등록을 취소하시겠습니까?" - // HIG에 따라 Cancel이 왼쪽 + let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) alert.addAction(okAction) alert.addAction(noAction) - present(alert, animated: true, completion: nil) + present(alert, animated: true) } @objc func editButtonDidTap(_ sender: UIButton) { - let okAction: UIAlertAction - var title = "" - var message = "" + let title = portfolioId == -1 ? "포트폴리오 수정하기" : "포트폴리오 등록하기" + let message = portfolioId == -1 ? "\n포트폴리오를 수정하시겠습니까?" : "\n포트폴리오를 등록하시겠습니까?" - if portfolioId == -1 { - title = "포트폴리오 수정하기" - message = "\n포트폴리오를 수정하시겠습니까?" - okAction = UIAlertAction(title: "예", style: .default) { [weak self] _ in - // TODO: 포트폴리오 수정 - } - } else { - title = "포트폴리오 등록하기" - message = "\n포트폴리오를 등록하시겠습니까?" - okAction = UIAlertAction(title: "예", style: .default) { [weak self] _ in - // TODO: 포트폴리오 생성 - } + let okAction = UIAlertAction(title: "예", style: .default) { [weak self] _ in + // TODO: 포트폴리오 수정/등록 } - - let noAction = UIAlertAction(title: "아니오", style: .cancel, handler: nil) + let noAction = UIAlertAction(title: "아니오", style: .cancel) let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) alert.addAction(okAction) alert.addAction(noAction) - present(alert, animated: true, completion: nil) + present(alert, animated: true) } - + @IBAction func trashButtonDidTap(_ sender: UIButton) { - let alert = UIAlertController(title: "포트폴리오 삭제하기", message: "\n포트폴리오를 삭제하시겠습니까?", preferredStyle: .alert) let okAction = UIAlertAction(title: "예", style: .default) { [weak self] _ in - self?.isBlock=true + self?.isBlock = true // TODO: 포트폴리오 삭제 } - let noAction = UIAlertAction( - title: "아니오", - style: .cancel, - handler : nil - ) - // HIG에 따라 Cancel이 왼쪽 + let noAction = UIAlertAction(title: "아니오", style: .cancel) + alert.addAction(okAction) alert.addAction(noAction) - present(alert, animated: true, completion: nil) + + present(alert, animated: true) } } -//MARK: - UICollectionViewDataSource -extension ArtistPortfolioEditingViewController : UICollectionViewDataSource { +// MARK: - UICollectionViewDataSource +extension ArtistPortfolioEditingViewController: UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - if collectionView == makeupCategoryCollectionView{ + if collectionView == makeupCategoryCollectionView { return portfolioCategories.count - }else { + } else { return imageCount == 3 ? 3 : imageCount + 1 } } + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { if collectionView == makeupCategoryCollectionView { guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ArtistMakeupTagCollectionViewCell.className, for: indexPath) as? ArtistMakeupTagCollectionViewCell else { return UICollectionViewCell() } let tagName = portfolioCategories[indexPath.row].korName cell.makeupTagLabel.text = tagName - if let selectedCategory = selectedCategory { - if selectedCategory == portfolioCategories[indexPath.row] { - cell.selected() - } else { - } + if let selectedCategory = selectedCategory, selectedCategory == portfolioCategories[indexPath.row] { + cell.selected() } else { + cell.deSelected() } return cell - }else { + } else { guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PortfolioImageCollectionViewCell.className, for: indexPath) as? PortfolioImageCollectionViewCell else { return UICollectionViewCell() } - // 이미지 3개 미만일 경우 첫 셀은 기본 이미지 - if imageCount == 3 { - cell.configure(image: portfolioImage[imageCount-1 - indexPath.row]) - }else { - if indexPath.row != 0 { - cell.configure(image: portfolioImage[imageCount - indexPath.row]) - } - } + cell.hideDeleteButton(imageCount != 3 && indexPath.row == 0) + cell.configure(image: imageCount == 3 ? portfolioImage[imageCount - 1 - indexPath.row] : (indexPath.row != 0 ? portfolioImage[imageCount - indexPath.row] : UIImage(named: "portfolio_image") ?? UIImage())) cell.delegate = self return cell } } } -//MARK: - UICollectionViewDelegate -extension ArtistPortfolioEditingViewController : UICollectionViewDelegate { +// MARK: - UICollectionViewDelegate +extension ArtistPortfolioEditingViewController: UICollectionViewDelegate { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { if collectionView == makeupCategoryCollectionView { - // 선택된 indexPath에 대한 셀을 가져오기 if let selectedCell = collectionView.cellForItem(at: indexPath) as? ArtistMakeupTagCollectionViewCell { - // 선택된 셀에 대한 작업 수행 selectedCell.selected() selectedCategory = portfolioCategories[indexPath.row] } - // 나머지 indexPath에 대한 셀을 가져와서 작업 수행 for visibleIndexPath in collectionView.indexPathsForVisibleItems { - if visibleIndexPath != indexPath, - let deselectedCell = collectionView.cellForItem(at: visibleIndexPath) as? ArtistMakeupTagCollectionViewCell { - // 선택되지 않은 셀에 대한 작업 수행 + if visibleIndexPath != indexPath, let deselectedCell = collectionView.cellForItem(at: visibleIndexPath) as? ArtistMakeupTagCollectionViewCell { deselectedCell.deSelected() } } } else { - //TODO: 이미지 변경 혹은 추가 + selectedImageIndexPath = indexPath.row let picker = PHPickerViewController(configuration: configuration) picker.delegate = self - self.present(picker, animated: true, completion: nil) - if indexPath.row == 0 && portfolioImage.count < 3 { - // 추가 후 데이터 리로드 - - }else { - // 변경 - - } - imageCount += 1 + self.present(picker, animated: true) portfolioImageCollectionView.reloadData() } } } -//MARK: - UICollectionViewDelegateFlowLayout +// MARK: - UICollectionViewDelegateFlowLayout extension ArtistPortfolioEditingViewController: UICollectionViewDelegateFlowLayout { func collectionView( _ collectionView: UICollectionView, @@ -286,41 +240,44 @@ extension ArtistPortfolioEditingViewController: UICollectionViewDelegateFlowLayo break } return CGSize(width: width, height: 27) - }else { - return CGSize(width: collectionView.bounds.height, height: collectionView.bounds.height) + } else { + return CGSize(width: 80, height: 82) } } + func collectionView( _ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int ) -> CGFloat { - return CGFloat(7) + return 7 } + func collectionView( _ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int ) -> CGFloat { - return CGFloat(15) + return 15 } } -//MARK: - API 호출 +// MARK: - API Calls extension ArtistPortfolioEditingViewController { private func getPortfolioDetail() { - + // TODO: 포트폴리오 세부조회 API } - private func createPortfolio(){ - + private func createPortfolio() { + // TODO: 포트폴리오 추가 API } private func editPortfolio() { + // TODO: 포트폴리오 수정 API } } -// MARK: - keyboard tabGesture +// MARK: - Keyboard Handling extension ArtistPortfolioEditingViewController { func setupDismissKeyboardOnTapGesture() { let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) @@ -333,35 +290,55 @@ extension ArtistPortfolioEditingViewController { } } -// MARK: - textView PlaceHolder +// MARK: - UITextViewDelegate extension ArtistPortfolioEditingViewController: UITextViewDelegate { func textViewDidChange(_ textView: UITextView) { - if let text = textView.text, !text.isEmpty { - self.infoTextViewPlaceHolderLabel.isHidden = true - } else { - self.infoTextViewPlaceHolderLabel.isHidden = false - } + infoTextViewPlaceHolderLabel.isHidden = !textView.text.isEmpty } } +// MARK: - PortfolioImageCollectionViewCellDelegate extension ArtistPortfolioEditingViewController: PortfolioImageCollectionViewCellDelegate { - func deleteButtonTapped() { - //TODO: 삭제 후 콜렉션 뷰 새로고침 + func deleteButtonTapped(_ cell: PortfolioImageCollectionViewCell) { + guard let indexPath = portfolioImageCollectionView.indexPath(for: cell) else { return } + portfolioImage[2 - indexPath.row] = UIImage() + moveEmptyImagesToEnd() + imageCount -= 1 + if imageCount == 2 { + let temp = portfolioImage[0] + portfolioImage[0] = portfolioImage[1] + portfolioImage[1] = temp + } + portfolioImageCollectionView.reloadData() + } + + private func moveEmptyImagesToEnd() { + portfolioImage.sort { (first, second) -> Bool in + if first == UIImage() && second == UIImage() { return false } + if first == UIImage() { return false } + if second == UIImage() { return true } + return true + } } } +// MARK: - PHPickerViewControllerDelegate extension ArtistPortfolioEditingViewController: PHPickerViewControllerDelegate { - func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) { - picker.dismiss(animated: true, completion: nil) + picker.dismiss(animated: true) let itemProvider = results.first?.itemProvider - if let itemProvider = itemProvider, - itemProvider.canLoadObject(ofClass: UIImage.self) { - itemProvider.loadObject(ofClass: UIImage.self) { image, error in + if let itemProvider = itemProvider, itemProvider.canLoadObject(ofClass: UIImage.self) { + itemProvider.loadObject(ofClass: UIImage.self) { [weak self] image, error in DispatchQueue.main.async { - guard let selectedImage = image as? UIImage else { return } - // TODO: 선택 indexPath.row에 따라 변경 필요 - self.portfolioImage.append(selectedImage) + guard let self = self, let selectedImage = image as? UIImage else { return } + if self.imageCount == 3 { + self.portfolioImage[2 - self.selectedImageIndexPath] = selectedImage + } else { + self.portfolioImage[self.imageCount - self.selectedImageIndexPath] = selectedImage + if self.selectedImageIndexPath == 0 { + self.imageCount += 1 + } + } self.portfolioImageCollectionView.reloadData() } } diff --git a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.xib b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.xib index a4fe02d..1b2c738 100644 --- a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.xib +++ b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.xib @@ -44,19 +44,19 @@ - + @@ -66,13 +66,13 @@ - + @@ -82,13 +82,13 @@ - + @@ -101,7 +101,7 @@ - + @@ -111,16 +111,16 @@ - + - + diff --git a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift index 74de667..7eb8031 100644 --- a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift +++ b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift @@ -1,32 +1,31 @@ -// -// PortfolioImageCollectionViewCell.swift -// MEME -// -// Created by 황채웅 on 7/30/24. -// - import UIKit +import SnapKit -protocol PortfolioImageCollectionViewCellDelegate: ArtistPortfolioEditingViewController{ - func deleteButtonTapped() +protocol PortfolioImageCollectionViewCellDelegate: AnyObject { + func deleteButtonTapped(_ cell: PortfolioImageCollectionViewCell) } class PortfolioImageCollectionViewCell: UICollectionViewCell { - private var deleteButton: UIButton{ + private lazy var deleteButton: UIButton = { let button = UIButton() + button.setImage(UIImage(named: "ic_delete"), for: .normal) button.addTarget(self, action: #selector(deleteButtonTapped), for: .touchUpInside) return button - } - private var portfolioImageView: UIImageView{ - let imageView = UIImageView() + }() + + private lazy var portfolioImageView: UIImageView = { + let imageView = UIImageView(image: UIImage(named: "portfolio_image")) + imageView.contentMode = .scaleAspectFill + imageView.clipsToBounds = true return imageView - } + }() + weak var delegate: PortfolioImageCollectionViewCellDelegate? override init(frame: CGRect) { super.init(frame: frame) - addSubview(deleteButton) - addSubview(portfolioImageView) + contentView.addSubview(portfolioImageView) + contentView.addSubview(deleteButton) portfolioImageView.snp.makeConstraints { make in make.leading.trailing.top.bottom.equalToSuperview() @@ -35,18 +34,23 @@ class PortfolioImageCollectionViewCell: UICollectionViewCell { make.trailing.top.equalToSuperview() make.height.width.equalTo(18) } - contentView.layer.cornerRadius = 10 + + contentView.layer.cornerRadius = 5 + contentView.layer.masksToBounds = true } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } - @objc func deleteButtonTapped(_ sender: UIButton){ - delegate?.deleteButtonTapped() + @objc func deleteButtonTapped(_ sender: UIButton) { + delegate?.deleteButtonTapped(self) } - func configure(image: UIImage){ + func configure(image: UIImage) { portfolioImageView.image = image } + func hideDeleteButton(_ option: Bool) { + deleteButton.isHidden = option + } } diff --git a/MEME/MEME/Assets.xcassets/ArtistHome/portfolio_image.imageset/Contents.json b/MEME/MEME/Assets.xcassets/ArtistHome/portfolio_image.imageset/Contents.json new file mode 100644 index 0000000..bd486aa --- /dev/null +++ b/MEME/MEME/Assets.xcassets/ArtistHome/portfolio_image.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "filename" : "portfolio_image.svg", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MEME/MEME/Assets.xcassets/ArtistHome/portfolio_image.imageset/portfolio_image.svg b/MEME/MEME/Assets.xcassets/ArtistHome/portfolio_image.imageset/portfolio_image.svg new file mode 100644 index 0000000..e4b8c9f --- /dev/null +++ b/MEME/MEME/Assets.xcassets/ArtistHome/portfolio_image.imageset/portfolio_image.svg @@ -0,0 +1,6 @@ + + + + + + From 31e2edc9719d81b591b68676549eae7e7d348b79 Mon Sep 17 00:00:00 2001 From: woongaaaa Date: Sat, 10 Aug 2024 16:26:54 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=EC=BD=94=EB=93=9C=EB=A6=AC=EB=B7=B0=20?= =?UTF-8?q?=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PortfolioImageCollectionViewCell.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift index 7eb8031..a57949b 100644 --- a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift +++ b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift @@ -8,7 +8,7 @@ protocol PortfolioImageCollectionViewCellDelegate: AnyObject { class PortfolioImageCollectionViewCell: UICollectionViewCell { private lazy var deleteButton: UIButton = { let button = UIButton() - button.setImage(UIImage(named: "ic_delete"), for: .normal) + button.setImage(.icDelete, for: .normal) button.addTarget(self, action: #selector(deleteButtonTapped), for: .touchUpInside) return button }() @@ -16,7 +16,6 @@ class PortfolioImageCollectionViewCell: UICollectionViewCell { private lazy var portfolioImageView: UIImageView = { let imageView = UIImageView(image: UIImage(named: "portfolio_image")) imageView.contentMode = .scaleAspectFill - imageView.clipsToBounds = true return imageView }() @@ -26,17 +25,19 @@ class PortfolioImageCollectionViewCell: UICollectionViewCell { super.init(frame: frame) contentView.addSubview(portfolioImageView) contentView.addSubview(deleteButton) - + makeConstraints() + contentView.layer.cornerRadius = 5 + contentView.layer.masksToBounds = true + } + + private func makeConstraints(){ portfolioImageView.snp.makeConstraints { make in - make.leading.trailing.top.bottom.equalToSuperview() + make.edges.equalToSuperview() } deleteButton.snp.makeConstraints { make in make.trailing.top.equalToSuperview() make.height.width.equalTo(18) } - - contentView.layer.cornerRadius = 5 - contentView.layer.masksToBounds = true } required init?(coder: NSCoder) {