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
23 changes: 11 additions & 12 deletions Pinit/Pinit/Views/PinDetail/NewPinReviewPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class NewPinReviewPanel: UIView {
.value
textField.leftView = UIView(frame: CGRect(x: 0, y: 0, width: 10, height: 0))
textField.leftViewMode = .always

textField.autocorrectionType = .no
textField.autocapitalizationType = .none
textField.spellCheckingType = .no
textField.placeholder = "내용을 입력해주세요"
return textField
}()
Expand All @@ -55,21 +57,13 @@ class NewPinReviewPanel: UIView {
let largeConfig = UIImage.SymbolConfiguration(pointSize: 30, weight: .bold, scale: .default)
let largeImage = UIImage(systemName: "arrow.right.circle.fill")?.withConfiguration(largeConfig)
button.setImage(largeImage, for: .normal)
button.tintColor = .systemGreen
button.tintColor = DesignSystemColor.Lavender.value
return button
}()

public lazy var topBorder: UIView = {
let border = UIView()
border.backgroundColor = .systemGray4
return border
}()



private func addComponents() {
self.addSubviews(newReviewPanel)
newReviewPanel.addSubviews(topBorder, reviewDate, reviewText, commitButton)
newReviewPanel.addSubviews(reviewDate, reviewText, commitButton)


newReviewPanel.snp.makeConstraints {
Expand All @@ -85,10 +79,11 @@ class NewPinReviewPanel: UIView {

reviewText.snp.makeConstraints {
$0.top.equalTo(reviewDate.snp.bottom).offset(10)
$0.width.equalTo(340)
// $0.width.equalTo(340)
$0.height.equalTo(40)

$0.leading.equalToSuperview().offset(10)
$0.trailing.equalTo(commitButton.snp.leading).offset(-10)

}

Expand All @@ -105,3 +100,7 @@ class NewPinReviewPanel: UIView {
#Preview {
NewPinReviewPanel()
}

#Preview {
PinDetailViewController(PinEntity.sampleData[0], isPin: true)
}
83 changes: 55 additions & 28 deletions Pinit/Pinit/Views/PinDetail/PinDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,21 @@ final class PinDetailViewController: UIViewController {
setupReviewTable()
addComponents()
loadReviewData()
setUpKeyboard()

reviewPanelContainer.commitButton.addTarget(self, action: #selector(onCommitButtonTapped), for: .touchUpInside)
}

private func setUpKeyboard() {
NotificationCenter.default.addObserver(self,
selector: #selector(keyboardWillShow),
name: UIResponder.keyboardWillShowNotification,
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(keyboardWillHide),
name: UIResponder.keyboardWillHideNotification,
object: nil)
}

private func loadReviewData() {
self.useCase.fetchAllReviewsByPinID(pinID: self.pinEntity.pin_id) {[weak self] items in
Expand All @@ -67,15 +78,15 @@ final class PinDetailViewController: UIViewController {
let lat = pinEntity.latitude
let long = pinEntity.longitude

let center = CLLocationCoordinate2D(latitude: lat, longitude: long) // San Francisco, CA
let center = CLLocationCoordinate2D(latitude: lat, longitude: long)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005))

map.setRegion(region, animated: true)
map.showsUserLocation = false
map.isUserInteractionEnabled = false

let annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2D(latitude: lat, longitude: long) // San Francisco, CA
annotation.coordinate = CLLocationCoordinate2D(latitude: lat, longitude: long)
annotation.title = pinEntity.title
map.addAnnotation(annotation)

Expand Down Expand Up @@ -175,6 +186,20 @@ extension PinDetailViewController {
self.pinTableView.reloadData()
}

@objc func doneBtnClicked() {
view.endEditing(true)
}

//MARK: 키보드가 나타낼때 화면을 -300
@objc func keyboardWillShow(notification: NSNotification) {
view.frame.origin.y = -200
}

//MARK: 키보드가 사라질 때 동작
@objc func keyboardWillHide(notification: NSNotification) {
view.frame.origin.y = 0
}

@objc func pinMenuButtonTapped() {
let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

Expand All @@ -185,7 +210,7 @@ extension PinDetailViewController {
self.useCase.updatePin(pin: pin)
self.updatePinNoti!(self.pinEntity, pin)
self.pinEntity = pin
#warning("업데이트 후 헤더 업데이트 해줘야함ㅇㅇ")
self.pinTableView.reloadData()
}
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true, completion: nil)
Expand Down Expand Up @@ -216,6 +241,33 @@ extension PinDetailViewController {
// MARK: - Delegate
extension PinDetailViewController: UITableViewDataSource, UITableViewDelegate {

// viewForHeaderInSection
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = PinDetailHeader(entity: pinEntity)
if !isPin {
header.pinMenuButton.isHidden = true
header.reviewSectionTitle.text = "방명록"
}
header.pinMenuButton.addTarget(self, action: #selector(pinMenuButtonTapped), for: .touchUpInside)
return header
}



// estimatedHeightForHeaderInSection
func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat {
return 100
}

// heightForHeaderInSection
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return UITableView.automaticDimension
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 70
}

// didSelectRowAt
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: false)
Expand Down Expand Up @@ -252,32 +304,7 @@ extension PinDetailViewController: UITableViewDataSource, UITableViewDelegate {

}

// viewForHeaderInSection
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = PinDetailHeader(entity: pinEntity)
if !isPin {
header.pinMenuButton.isHidden = true
header.reviewSectionTitle.text = "방명록"
}
header.pinMenuButton.addTarget(self, action: #selector(pinMenuButtonTapped), for: .touchUpInside)
return header
}



// estimatedHeightForHeaderInSection
func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat {
return 100
}

// heightForHeaderInSection
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return UITableView.automaticDimension
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 70
}
}


Expand Down
51 changes: 28 additions & 23 deletions Pinit/Pinit/Views/PinEdit/PinEditViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ enum PinMode {


final class PinEditViewController: UIViewController, UITextViewDelegate {
private var pinEntity: PinEntity
private var pinEntity: PinEntity!
var isAdded: ((PinEntity) -> Void)? // 핀추가가 됐을때 호출되는 클로저 (홈에서만 사용)
private var pickedImage: UIImage?

private var mapView: MKMapView
private var mapView: MKMapView!

private let saveButton : UIButton = {
let button = UIButton()
Expand All @@ -41,6 +41,9 @@ final class PinEditViewController: UIViewController, UITextViewDelegate {
textview.textAlignment = .center
textview.textColor = UIColor.black
textview.font = UIFont.systemFont(ofSize: 16)
textview.autocorrectionType = .no
textview.autocapitalizationType = .none
textview.spellCheckingType = .no
return textview
}()

Expand All @@ -58,6 +61,9 @@ final class PinEditViewController: UIViewController, UITextViewDelegate {
.value
textfield.leftView = UIView(frame: CGRect(x: 0, y: 0, width: 16, height: 0))
textfield.leftViewMode = .always
textfield.autocorrectionType = .no
textfield.autocapitalizationType = .none
textfield.spellCheckingType = .no
return textfield
}()

Expand Down Expand Up @@ -117,6 +123,16 @@ final class PinEditViewController: UIViewController, UITextViewDelegate {
return toolbar
}()

private func setImageToCameraButton(image: UIImage?) {
guard let image else { return }
self.pickedImage = image
cameraButton.backgroundColor = .clear
cameraButton.setImage(nil, for: .normal)
cameraButton.clipsToBounds = true
cameraButton.layer.cornerRadius = 75
cameraButton.setBackgroundImage(image, for: .normal)
}

// MARK: - viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -127,9 +143,10 @@ final class PinEditViewController: UIViewController, UITextViewDelegate {
}

init(pinMode: PinMode) {
super.init(nibName: nil, bundle: nil)

switch pinMode {
case let .create(latitude, longitude):
print("\(latitude), \(longitude)")
self.pinEntity = PinEntity(
pin_id: UUID(),
title: "",
Expand All @@ -142,13 +159,14 @@ final class PinEditViewController: UIViewController, UITextViewDelegate {
)

case let .edit(PinEntity):
print(PinEntity)
self.pinEntity = PinEntity
print("편집 모드입니다")
dateLabel.text = pinEntity.date.koreanDateString()
titleTextField.text = pinEntity.title
contentTextView.text = pinEntity.description
self.setImageToCameraButton(image: pinEntity.mediaPath)
}


let map = MKMapView()
let lat = pinEntity.latitude
let long = pinEntity.longitude
Expand All @@ -165,7 +183,6 @@ final class PinEditViewController: UIViewController, UITextViewDelegate {

mapView = map

super.init(nibName: nil, bundle: nil)
}

required init?(coder: NSCoder) {
Expand Down Expand Up @@ -198,8 +215,9 @@ final class PinEditViewController: UIViewController, UITextViewDelegate {

weatherImage.snp.makeConstraints{
$0.top.equalTo(mapView.snp.bottom).offset(10)
$0.leading.equalTo(view.snp.centerX).offset(100)
$0.height.width.equalTo(30)
// $0.leading.equalTo(view.snp.centerX).offset(100)
$0.trailing.equalToSuperview().inset(20)
$0.height.width.equalTo(35)
}

dateLabel.snp.makeConstraints{
Expand Down Expand Up @@ -255,7 +273,6 @@ final class PinEditViewController: UIViewController, UITextViewDelegate {

pinEntity.title = titleTextField.text ?? ""
pinEntity.description = contentTextView.text ?? ""

pinEntity.mediaPath = pickedImage

isAdded?(pinEntity)
Expand Down Expand Up @@ -314,7 +331,7 @@ final class PinEditViewController: UIViewController, UITextViewDelegate {

//MARK: 키보드가 나타낼때 화면을 -300
@objc func keyboardWillShow(notification: NSNotification) {
view.frame.origin.y = -300
view.frame.origin.y = -250
}

//MARK: 키보드가 사라질 때 동작
Expand Down Expand Up @@ -344,19 +361,7 @@ extension PinEditViewController: UIImagePickerControllerDelegate, UINavigationCo

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let selectedImage = info[.editedImage] as? UIImage ?? info[.originalImage] as? UIImage {
self.pickedImage = selectedImage
cameraButton.backgroundColor = .clear
cameraButton.setImage(nil, for: .normal)
//
// // 이미지를 버튼 크기에 맞게 조정하여 설정
// let resizedImage = resizeImage(image: pickedImage, targetSize: CGSize(width: 150, height: 150))

cameraButton.clipsToBounds = true
cameraButton.layer.cornerRadius = 75
cameraButton.setBackgroundImage(pickedImage, for: .normal)

// 선택한 이미지를 pinEntity에 저장 (나중에 경로로 변환하는 로직 추가 필요)
// pinEntity?.mediaPath = ...
setImageToCameraButton(image: selectedImage)
}
picker.dismiss(animated: true, completion: nil)
}
Expand Down