From 5e7ca265b4ea168d0f2e8d8643211c723d85bdb5 Mon Sep 17 00:00:00 2001 From: lkhwan0204 Date: Fri, 21 Mar 2025 11:13:23 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[CHORE]=20#19=20enum=20case=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84,=20=EC=BD=94=EB=93=9C=20=EB=B3=B4=EA=B8=B0=20?= =?UTF-8?q?=EC=89=BD=EA=B2=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/PinEdit/PinEditViewController.swift | 183 +++++++++--------- 1 file changed, 92 insertions(+), 91 deletions(-) diff --git a/Pinit/Pinit/Views/PinEdit/PinEditViewController.swift b/Pinit/Pinit/Views/PinEdit/PinEditViewController.swift index d074a45..e515fe1 100644 --- a/Pinit/Pinit/Views/PinEdit/PinEditViewController.swift +++ b/Pinit/Pinit/Views/PinEdit/PinEditViewController.swift @@ -9,19 +9,31 @@ import UIKit import MapKit import SnapKit +enum PinMode { + case create(latitude: Double, longtitude: Double) + case edit +} + final class PinEditViewController: UIViewController, UITextViewDelegate { - private var mapView: MKMapView! //mapview 불러옴 - private let datebutton = UIButton() // leftbutton을 클래스 프로퍼티로 변경 + private var mapView: MKMapView! + private let pinmode: PinMode = .edit override func viewDidLoad() { super.viewDidLoad() - self.view.backgroundColor = .white + switch pinmode { + case let .create(latitude, longtitude): + print("\(latitude), \(longtitude)") + case .edit: + print("편집 모드입니다") + } + + //MARK: mapView 설정 mapView = MKMapView(frame: self.view.bounds) //mkmapview 초기화 및 뷰 추가함 mapView = MKMapView(frame: CGRect(x: 0, y: 60, width: self.view.bounds.width, height: self.view.bounds.height / 4)) //화면의 1/4만 나오게 함 - self.view.addSubview(mapView) //mapview 뷰에 보이게 + setUpKeyboard() let center = CLLocationCoordinate2D(latitude: 37.506446, longitude: 126.885397) //중심좌표 @@ -29,8 +41,7 @@ final class PinEditViewController: UIViewController, UITextViewDelegate { mapView.setRegion(region, animated: true) - // 지도 오른쪽 위에 닫기 버튼 추가, xmark.circle.fill - let closeButton = UIButton(type: .system) + //MARK: 지도 오른쪽 위에 닫기 버튼 추가, xmark.circle.fill if let closeImage = UIImage(systemName: "xmark.circle.fill") { let largeConfig = UIImage.SymbolConfiguration(pointSize: 45, weight: .bold, scale: .default) let largeImage = closeImage.withConfiguration(largeConfig) @@ -39,47 +50,19 @@ final class PinEditViewController: UIViewController, UITextViewDelegate { closeButton.tintColor = .black closeButton.alpha = 0.7 // 투명도 50% 설정 - self.view.addSubview(closeButton) - - // Auto Layout 설정 - closeButton.snp.makeConstraints { - $0.top.equalToSuperview().offset(65) // 상단에서 65포인트 - $0.trailing.equalToSuperview().offset(-5) // 오른쪽에서 5 - $0.width.height.equalTo(40) // 버튼 크기 - } - - //왼쪽 기록 날짜 버튼 + //MARK: 왼쪽 기록 날짜 버튼 datebutton.backgroundColor = .clear datebutton.layer.cornerRadius = 10 datebutton.setTitle("3월 17일", for: .normal) //for: .normal은 아무런 상호작용 없을때 상태 - self.view.addSubview(datebutton) //뷰에 leftbutton 보여줌 datebutton.setTitleColor(UIColor.black, for: .normal) // 글자색을 검은색으로 변경 - //오토레이아웃 설정 - datebutton.snp.makeConstraints{ - $0.leading.equalToSuperview().offset(10) //왼쪽에서 10 떨어짐 - $0.top.equalToSuperview().offset(300) //탑에서 300 - $0.width.equalTo(180) //너비 200 - $0.height.equalTo(30) //높이 30 - } - //오른쪽 날씨 버튼 - let weatherbutton = UIButton() + //MARK: 오른쪽 날씨 버튼 weatherbutton.layer.cornerRadius = 10 weatherbutton.setTitle("맑음", for: .normal) weatherbutton.setTitleColor(UIColor.black, for: .normal) // 글자색을 검은색으로 변경 - self.view.addSubview(weatherbutton) - - //오토레이아웃 설정 - weatherbutton.snp.makeConstraints{ - $0.leading.equalToSuperview().offset(210) - $0.top.equalToSuperview().offset(300) - $0.width.equalTo(180) - $0.height.equalTo(30) - } - - //그 아래 카메라 버튼 - let camerabutton = UIButton() + + //MARK: 아래 카메라 버튼 camerabutton.backgroundColor = .white camerabutton.layer.cornerRadius = 75 camerabutton.layer.shadowColor = UIColor.black.cgColor // 색깔 @@ -97,22 +80,7 @@ final class PinEditViewController: UIViewController, UITextViewDelegate { camerabutton.addTarget(self, action: #selector(cameraButtonTapped), for: .touchUpInside) - self.view.addSubview(camerabutton) - //사진 배경 흰색, 안에 아이콘을 검은색 - - // Auto Layout 설정 - camerabutton.snp.makeConstraints{ - $0.centerX.equalToSuperview() - $0.centerY.equalToSuperview() - $0.width.equalTo(150) - $0.height.equalTo(150) - - } - - // 배경 흰색, stroke를 회색 - // 제목 작성 버튼 - let titlefield = UITextField() - titlefield.backgroundColor = .white + //MARK: 제목 작성 버튼 titlefield.layer.borderColor = UIColor(red: 169/255, green: 169/255, blue: 169/255, alpha: 1).cgColor // #A9A9A9 (다크 라이트 그레이) titlefield.layer.borderWidth = 2 // 테두리 두께 설정 titlefield.textColor = .black @@ -126,17 +94,7 @@ final class PinEditViewController: UIViewController, UITextViewDelegate { titlefield.leftView = UIView(frame: CGRect(x: 0, y: 0, width: 16, height: 0)) // 이거 개쩜 제목 작성 맨 앞에 여백을 주는거임 titlefield.leftViewMode = .always //항상 - self.view.addSubview(titlefield) - - titlefield.snp.makeConstraints{ - $0.leading.equalToSuperview().offset(20) - $0.top.equalToSuperview().offset(540) - $0.width.equalTo(360) - $0.height.equalTo(40) - } - - // 추가메모 텍스트뷰 추가 - let contentTextView = UITextView() + //MARK: 추가메모 텍스트뷰 추가 contentTextView.backgroundColor = .white contentTextView.layer.borderColor = UIColor(red: 169/255, green: 169/255, blue: 169/255, alpha: 1).cgColor // #A9A9A9 (다크 라이트 그레이) contentTextView.layer.borderWidth = 2 // 테두리 두께 설정 @@ -145,34 +103,17 @@ final class PinEditViewController: UIViewController, UITextViewDelegate { contentTextView.textAlignment = .center contentTextView.textColor = UIColor.black contentTextView.font = UIFont.systemFont(ofSize: 16) - self.view.addSubview(contentTextView) - - contentTextView.snp.makeConstraints { - $0.leading.equalToSuperview().offset(20) - $0.top.equalTo(titlefield.snp.bottom).offset(10) - $0.width.equalTo(360) - $0.height.equalTo(150) - } contentTextView.delegate = self - //저장 버튼 - let savebutton = UIButton() + //MARK: 저장 버튼 savebutton.backgroundColor = UIColor(red: 28/255, green: 70/255, blue: 245/255, alpha: 1) // #FF8C42 (딥 오렌지) savebutton.setTitle("저장", for: .normal) savebutton.layer.cornerRadius = 10 - self.view.addSubview(savebutton) - - //오토레이아웃 설정 - savebutton.snp.makeConstraints{ - $0.leading.equalToSuperview().offset(130) - $0.top.equalToSuperview().offset(760) - $0.width.equalTo(150) - $0.height.equalTo(55) - } + setui() - //키보드 완료 버튼 + //MARK: 키보드 완료 버튼 let keyboardToolbar = UIToolbar() let flexBarButton = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) let doneBarButton = UIBarButtonItem(title: "완료", style: .plain, target: self, action: #selector(doneBtnClicked)) @@ -184,13 +125,68 @@ final class PinEditViewController: UIViewController, UITextViewDelegate { } + //MARK: 오토레이아웃 정리 + let savebutton = UIButton() + let contentTextView = UITextView() + let titlefield = UITextField() + let camerabutton = UIButton() + let weatherbutton = UIButton() + private let datebutton = UIButton() + let closeButton = UIButton(type: .system) + func setui() { + self.view.addSubviews(savebutton, contentTextView, titlefield, camerabutton, weatherbutton, datebutton, closeButton) + + savebutton.snp.makeConstraints{ + $0.leading.equalToSuperview().offset(130) + $0.top.equalToSuperview().offset(760) + $0.width.equalTo(150) + $0.height.equalTo(55) + } + contentTextView.snp.makeConstraints { + $0.leading.equalToSuperview().offset(20) + $0.top.equalTo(titlefield.snp.bottom).offset(10) + $0.width.equalTo(360) + $0.height.equalTo(150) + } + titlefield.snp.makeConstraints{ + $0.leading.equalToSuperview().offset(20) + $0.top.equalToSuperview().offset(540) + $0.width.equalTo(360) + $0.height.equalTo(40) + } + camerabutton.snp.makeConstraints{ + $0.centerX.equalToSuperview() + $0.centerY.equalToSuperview() + $0.width.equalTo(150) + $0.height.equalTo(150) + } + weatherbutton.snp.makeConstraints{ + $0.leading.equalToSuperview().offset(210) + $0.top.equalToSuperview().offset(300) + $0.width.equalTo(180) + $0.height.equalTo(30) + } + datebutton.snp.makeConstraints{ + $0.leading.equalToSuperview().offset(10) + $0.top.equalToSuperview().offset(300) + $0.width.equalTo(180) + $0.height.equalTo(30) + } + closeButton.snp.makeConstraints { + $0.top.equalToSuperview().offset(65) + $0.trailing.equalToSuperview().offset(-5) + $0.width.height.equalTo(40) + } + } + + //MARK: 키보드 닫기 @objc func doneBtnClicked() { - view.endEditing(true) // 키보드 닫기 + view.endEditing(true) } + //MARK: 카메라 선택, 사진 선택 @objc func cameraButtonTapped() { let actionSheet = UIAlertController(title: "사진 선택", message: "사진을 가져올 방법을 선택하세요.", preferredStyle: .actionSheet) - let cameraAction = UIAlertAction(title: "카메라", style: .default) { _ in self.presentImagePicker(sourceType: .camera) } @@ -198,14 +194,13 @@ final class PinEditViewController: UIViewController, UITextViewDelegate { self.presentImagePicker(sourceType: .photoLibrary) } let cancelAction = UIAlertAction(title: "취소", style: .cancel, handler: nil) - actionSheet.addAction(cameraAction) actionSheet.addAction(galleryAction) actionSheet.addAction(cancelAction) - present(actionSheet, animated: true, completion: nil) } + //MARK: 사진 선택하면 화면에 사진 띄우기 func presentImagePicker(sourceType: UIImagePickerController.SourceType) { guard UIImagePickerController.isSourceTypeAvailable(sourceType) else { return } @@ -217,6 +212,7 @@ final class PinEditViewController: UIViewController, UITextViewDelegate { present(imagePicker, animated: true, completion: nil) } + //MARK: 시스템에 알리는 키보드 상태 알림 func setUpKeyboard() { NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), @@ -228,14 +224,17 @@ final class PinEditViewController: UIViewController, UITextViewDelegate { object: nil) } + //MARK: 키보드가 나타낼때 화면을 -300 @objc func keyboardWillShow(notification: NSNotification) { - view.frame.origin.y = -300 //키보드가 나타날 때 동작 + view.frame.origin.y = -300 } + //MARK: 키보드가 사라질 때 동작 @objc func keyboardWillHide(notification: NSNotification) { - view.frame.origin.y = 0 //키보드가 사라질 때 동작 + view.frame.origin.y = 0 } + //MARK: 사용자가 텍스트뷰에 입력을 시작할 때 기본 안내 문구 func textViewDidBeginEditing(_ textView: UITextView) { if textView.text == "남기고자 하는 메모가 있다면 작성해주세요." { textView.text = "" @@ -243,6 +242,7 @@ final class PinEditViewController: UIViewController, UITextViewDelegate { } } + //MARK: 텍스트뷰가 비어있을 때 안내 메시지를 다시 표시 func textViewDidEndEditing(_ textView: UITextView) { if textView.text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { textView.text = "남기고자 하는 메모가 있다면 작성해주세요." @@ -251,6 +251,7 @@ final class PinEditViewController: UIViewController, UITextViewDelegate { } } +//MARK: PinEditViewController 내에서 사진 선택 기능을 쉽게 사용 extension PinEditViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate { func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { if let selectedImage = info[.editedImage] as? UIImage ?? info[.originalImage] as? UIImage { From cf5b9afc36429874ef344879dd3c275097f66624 Mon Sep 17 00:00:00 2001 From: lkhwan0204 Date: Fri, 21 Mar 2025 11:35:34 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[FIX]=20#19=20=EB=B0=B0=EA=B2=BD=20?= =?UTF-8?q?=ED=88=AC=EB=AA=85=EC=9D=B4=EC=97=88=EB=8D=98=EA=B1=B0=20?= =?UTF-8?q?=ED=9D=B0=EC=83=89=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95,=20x?= =?UTF-8?q?=EB=B2=84=ED=8A=BC=20=EB=88=84=EB=A5=B4=EB=A9=B4=20=EB=92=A4?= =?UTF-8?q?=EB=A1=9C=EA=B0=80=EA=B8=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Pinit/Pinit/Views/PinEdit/PinEditViewController.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Pinit/Pinit/Views/PinEdit/PinEditViewController.swift b/Pinit/Pinit/Views/PinEdit/PinEditViewController.swift index e515fe1..619455a 100644 --- a/Pinit/Pinit/Views/PinEdit/PinEditViewController.swift +++ b/Pinit/Pinit/Views/PinEdit/PinEditViewController.swift @@ -22,6 +22,8 @@ final class PinEditViewController: UIViewController, UITextViewDelegate { override func viewDidLoad() { super.viewDidLoad() + view.backgroundColor = .white + switch pinmode { case let .create(latitude, longtitude): print("\(latitude), \(longtitude)") @@ -49,6 +51,7 @@ final class PinEditViewController: UIViewController, UITextViewDelegate { } closeButton.tintColor = .black closeButton.alpha = 0.7 // 투명도 50% 설정 + closeButton.addTarget(self, action: #selector(dismissButtonTapped), for: .touchUpInside) //MARK: 왼쪽 기록 날짜 버튼 datebutton.backgroundColor = .clear @@ -224,6 +227,10 @@ final class PinEditViewController: UIViewController, UITextViewDelegate { object: nil) } + @objc func dismissButtonTapped() { + self.dismiss(animated: true) + } + //MARK: 키보드가 나타낼때 화면을 -300 @objc func keyboardWillShow(notification: NSNotification) { view.frame.origin.y = -300