Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Pinit/Pinit/Views/PastPin/PastPinViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ final class PastPinViewController: UIViewController {

//MARK: - 모든 PinEntity를 가져옵니다.
let pinData = PinEntity.sampleData

private let usecase: UseCase

//MARK: - properties
Expand Down Expand Up @@ -137,7 +138,8 @@ extension PastPinViewController : FSCalendarDelegate, FSCalendarDataSource, FSCa
extension PastPinViewController : PinCollectionViewAdapterDelegate {

func selectedItem(selected: PinEntity) { //화면 이동
print("selectedItem")
let vc = PinDetailViewController(selected)
self.present(vc, animated: true)
}

func deletedItem(deleted: PinEntity?) { //아이템 삭제 클릭시
Expand Down
260 changes: 141 additions & 119 deletions Pinit/Pinit/Views/PinEdit/PinEditViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,174 +2,191 @@
// PinEditViewController.swift
// Pinit
//
// Created by 안정흠이형메롱메롱메롱메롱바보바보바바바바보바보바보 on 3/12/25.
// 푸시할때 조심 씬델리게이트 바꿔라
// Created by 안정흠 on 3/12/25.
// Edited by 안세훈 on 3/21/25 lol

import UIKit
import MapKit
import SnapKit

enum PinMode {
case create(latitude: Double, longtitude: Double)
case edit
case edit(PinEntity : PinEntity)
}

final class PinEditViewController: UIViewController, UITextViewDelegate {

private var mapView: MKMapView!
private let pinmode: PinMode = .edit
var pinmode: PinMode?

override func viewDidLoad() {
super.viewDidLoad()

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()

private var mapView: MKMapView = {
let view = MKMapView()
let center = CLLocationCoordinate2D(latitude: 37.506446, longitude: 126.885397) //중심좌표
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05))
mapView.setRegion(region, animated: true)

view.setRegion(region, animated: true)
return view
}()

private let saveButton : UIButton = {
let button = UIButton()
button.backgroundColor = UIColor(red: 28/255, green: 70/255, blue: 245/255, alpha: 1) // #FF8C42 (딥 오렌지)
button.setTitle("저장", for: .normal)
button.layer.cornerRadius = 10
return button
}()

let contentTextView : UITextView = {
let textview = UITextView()
textview.backgroundColor = .white
textview.layer.borderColor = UIColor(red: 169/255, green: 169/255, blue: 169/255, alpha: 1).cgColor // #A9A9A9 (다크 라이트 그레이)
textview.layer.borderWidth = 2 // 테두리 두께 설정
textview.layer.cornerRadius = 5
textview.text = "남기고자 하는 메모가 있다면 작성해주세요."
textview.textAlignment = .center
textview.textColor = UIColor.black
textview.font = UIFont.systemFont(ofSize: 16)
return textview
}()

private let titleTextField : UITextField = {
let textfield = UITextField()
textfield.layer.borderColor = UIColor(red: 169/255, green: 169/255, blue: 169/255, alpha: 1).cgColor
textfield.layer.borderWidth = 2
textfield.textColor = .black
textfield.layer.cornerRadius = 5
textfield.attributedPlaceholder = NSAttributedString(
string: "제목 작성",
attributes: [NSAttributedString.Key.foregroundColor: UIColor.black]
)
textfield.font = DesignSystemFont.Pretendard_Bold14
.value
textfield.leftView = UIView(frame: CGRect(x: 0, y: 0, width: 16, height: 0))
textfield.leftViewMode = .always
return textfield
}()

private let cameraButton : UIButton = {
let button = UIButton()
//MARK: 아래 카메라 버튼
button.backgroundColor = .white
button.layer.cornerRadius = 75
button.layer.shadowColor = UIColor.black.cgColor // 색깔
button.layer.masksToBounds = false // 내부에 속한 요소들이 UIView 밖을 벗어날 때, 잘라낼 것인지. 그림자는 밖에 그려지는 것이므로 false 로 설정
button.layer.shadowOffset = CGSize(width: 0, height: 4) // 위치조정
button.layer.shadowRadius = 10 // 반경
button.layer.shadowOpacity = 0.5

if let cameraImage = UIImage(systemName: "camera.on.rectangle"){
let largeConfig = UIImage.SymbolConfiguration(pointSize: 60, weight: .regular, scale: .default)
let largeImage = cameraImage.withConfiguration(largeConfig)
button.setImage(largeImage, for: .normal)
}
button.tintColor = UIColor(red: 96/255, green: 99/255, blue: 104/255, alpha: 1)
button.imageView?.contentMode = .scaleAspectFit
button.addTarget(PinEditViewController.self, action: #selector(cameraButtonTapped), for: .touchUpInside)
return button
}()

private let weatherButton : UIButton = {
let button = UIButton()
button.layer.cornerRadius = 10
button.setTitle("맑음", for: .normal)
button.setTitleColor(UIColor.black, for: .normal) // 글자색을 검은색으로 변경
return button
}()

private let dateButton : UIButton = {
let button = UIButton()
button.backgroundColor = .clear
button.layer.cornerRadius = 10
button.setTitle("3월 17일", for: .normal)
button.setTitleColor(UIColor.black, for: .normal)
return button
}()

private let closeButton : UIButton = {
let button = UIButton()
//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)
closeButton.setImage(largeImage, for: .normal)
}
closeButton.tintColor = .black
closeButton.alpha = 0.7 // 투명도 50% 설정
closeButton.addTarget(self, action: #selector(dismissButtonTapped), for: .touchUpInside)

//MARK: 왼쪽 기록 날짜 버튼
datebutton.backgroundColor = .clear
datebutton.layer.cornerRadius = 10
datebutton.setTitle("3월 17일", for: .normal) //for: .normal은 아무런 상호작용 없을때 상태
datebutton.setTitleColor(UIColor.black, for: .normal) // 글자색을 검은색으로 변경


//MARK: 오른쪽 날씨 버튼
weatherbutton.layer.cornerRadius = 10
weatherbutton.setTitle("맑음", for: .normal)
weatherbutton.setTitleColor(UIColor.black, for: .normal) // 글자색을 검은색으로 변경

//MARK: 아래 카메라 버튼
camerabutton.backgroundColor = .white
camerabutton.layer.cornerRadius = 75
camerabutton.layer.shadowColor = UIColor.black.cgColor // 색깔
camerabutton.layer.masksToBounds = false // 내부에 속한 요소들이 UIView 밖을 벗어날 때, 잘라낼 것인지. 그림자는 밖에 그려지는 것이므로 false 로 설정
camerabutton.layer.shadowOffset = CGSize(width: 0, height: 4) // 위치조정
camerabutton.layer.shadowRadius = 10 // 반경
camerabutton.layer.shadowOpacity = 0.5
if let cameraImage = UIImage(systemName: "camera.on.rectangle"){
let largeConfig = UIImage.SymbolConfiguration(pointSize: 60, weight: .regular, scale: .default)
let largeImage = cameraImage.withConfiguration(largeConfig)
camerabutton.setImage(largeImage, for: .normal)
button.setImage(largeImage, for: .normal)
}
camerabutton.tintColor = UIColor(red: 96/255, green: 99/255, blue: 104/255, alpha: 1) // #606368 (다크 그레이)
camerabutton.imageView?.contentMode = .scaleAspectFit

camerabutton.addTarget(self, action: #selector(cameraButtonTapped), for: .touchUpInside)

//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
titlefield.layer.cornerRadius = 5
titlefield.attributedPlaceholder = NSAttributedString(
string: "제목 작성",
attributes: [NSAttributedString.Key.foregroundColor: UIColor.black] //제목작성 글자 흰색으로
)
titlefield.font = DesignSystemFont.Pretendard_Bold14
.value
titlefield.leftView = UIView(frame: CGRect(x: 0, y: 0, width: 16, height: 0)) // 이거 개쩜 제목 작성 맨 앞에 여백을 주는거임
titlefield.leftViewMode = .always //항상

//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 // 테두리 두께 설정
contentTextView.layer.cornerRadius = 5
contentTextView.text = "남기고자 하는 메모가 있다면 작성해주세요."
contentTextView.textAlignment = .center
contentTextView.textColor = UIColor.black
contentTextView.font = UIFont.systemFont(ofSize: 16)

contentTextView.delegate = self

//MARK: 저장 버튼
savebutton.backgroundColor = UIColor(red: 28/255, green: 70/255, blue: 245/255, alpha: 1) // #FF8C42 (딥 오렌지)
savebutton.setTitle("저장", for: .normal)
savebutton.layer.cornerRadius = 10
setui()


//MARK: 키보드 완료 버튼
let keyboardToolbar = UIToolbar()
button.tintColor = .black
button.alpha = 0.7 // 투명도 50% 설정
button.addTarget(PinEditViewController.self, action: #selector(dismissButtonTapped), for: .touchUpInside)
return button
}()

private let keyboardToolBar: UIToolbar = {
let toolbar = UIToolbar()
let flexBarButton = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let doneBarButton = UIBarButtonItem(title: "완료", style: .plain, target: self, action: #selector(doneBtnClicked))
keyboardToolbar.items = [flexBarButton, doneBarButton]
keyboardToolbar.sizeToFit()

titlefield.inputAccessoryView = keyboardToolbar
contentTextView.inputAccessoryView = keyboardToolbar

let doneBarButton = UIBarButtonItem(title: "완료", style: .plain, target: PinEditViewController.self, action: #selector(doneBtnClicked))
toolbar.items = [flexBarButton, doneBarButton]
toolbar.sizeToFit()
return toolbar
}()

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
SetUI()
SetMap()
viewmode()
setUpKeyboard()
}

//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)

func viewmode(){
switch pinmode {
case let .create(latitude, longtitude):
print("\(latitude), \(longtitude)")
case let .edit(PinEntity):
print(PinEntity)
// titleTextField.text = PinEntity.description
print("편집 모드입니다")
case .none:
print("?")
}
}

private func SetUI() {
titleTextField.inputAccessoryView = keyboardToolBar
contentTextView.inputAccessoryView = keyboardToolBar
contentTextView.delegate = self

self.view.addSubviews(mapView, saveButton, contentTextView, titleTextField, cameraButton, weatherButton, dateButton, closeButton)

savebutton.snp.makeConstraints{
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.top.equalTo(titleTextField.snp.bottom).offset(10)
$0.width.equalTo(360)
$0.height.equalTo(150)
}
titlefield.snp.makeConstraints{
titleTextField.snp.makeConstraints{
$0.leading.equalToSuperview().offset(20)
$0.top.equalToSuperview().offset(540)
$0.width.equalTo(360)
$0.height.equalTo(40)
}
camerabutton.snp.makeConstraints{
cameraButton.snp.makeConstraints{
$0.centerX.equalToSuperview()
$0.centerY.equalToSuperview()
$0.width.equalTo(150)
$0.height.equalTo(150)
}
weatherbutton.snp.makeConstraints{
weatherButton.snp.makeConstraints{
$0.leading.equalToSuperview().offset(210)
$0.top.equalToSuperview().offset(300)
$0.width.equalTo(180)
$0.height.equalTo(30)
}
datebutton.snp.makeConstraints{
dateButton.snp.makeConstraints{
$0.leading.equalToSuperview().offset(10)
$0.top.equalToSuperview().offset(300)
$0.width.equalTo(180)
Expand All @@ -182,6 +199,11 @@ final class PinEditViewController: UIViewController, UITextViewDelegate {
}
}

private func SetMap(){
mapView = MKMapView(frame: self.view.bounds)
mapView = MKMapView(frame: CGRect(x: 0, y: 60, width: self.view.bounds.width, height: self.view.bounds.height / 4))
}

//MARK: 키보드 닫기
@objc func doneBtnClicked() {
view.endEditing(true)
Expand Down