Skip to content

Commit

Permalink
πŸ”¨[FIX] #129 - ν˜„μƒμ†Œ μ•„μ΄μ½˜ 쀑볡 클릭 방지
Browse files Browse the repository at this point in the history
  • Loading branch information
jumining committed Mar 3, 2022
1 parent 84c61b0 commit 914c13e
Showing 1 changed file with 61 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,12 @@ class StudioMapViewController: UIViewController {
layoutMyLocationButton()
layoutSearchView()
layoutNavigaionBar()
getBottomSheetInfo()
totalStudioWithAPI()
setLatLngNotification()
showtmpStudioMarker()
tmpSetupMarker()
setupBottomSheetUI()
setupBottomSheetGestureRecognizer()
getBottomSheetInfo()
}

override func viewDidAppear(_ animated: Bool) {
getBottomSheetInfo()
}

// MARK: - init
Expand All @@ -113,26 +109,55 @@ class StudioMapViewController: UIViewController {
extension StudioMapViewController {

/// μ„œλ²„ λΆ€ν™œλ˜κΈ° μ „κΉŒμ§€ ν˜„μƒμ†Œ κ΄€λ ¨ κΈ°λŠ₯ ν…ŒμŠ€νŠΈν•  μž„μ‹œ ν•¨μˆ˜ (넀이버 κ·Έλ¦°νŒ©ν† λ¦¬μ— ν˜„μƒμ†Œ ν‘œμ‹œν•΄μ€Œ)
func showtmpStudioMarker() {
func tmpSetupMarker() {
let markertmp = NMFMarker(position: NMGLatLng(lat: 37.35940010181669, lng: 127.10475679570187))
markertmp.iconImage = NMFOverlayImage(image: Asset.icnStudio.image)
markertmp.mapView = self.mapView.mapView

/// 클릭 μ‹œ 이벀트 μ„€μ •
markertmp.touchHandler = { [weak self] (overlay: NMFOverlay) -> Bool in
if self?.clickCount == 1 { /// 이미 λ§ˆμ»€κ°€ 클릭된 경우 (쀑볡 클릭 ν—ˆμš©μ•ˆν•¨)
self?.clickCount = 0
markertmp.iconImage = NMFOverlayImage(image: Asset.icnStudio.image)
self?.hideBottomSheetAndGoBack()
let secondMarkertmp = NMFMarker(position: NMGLatLng(lat: 37.36161841308457, lng: 127.10566240106306))
secondMarkertmp.iconImage = NMFOverlayImage(image: Asset.icnStudio.image)
secondMarkertmp.mapView = self.mapView.mapView

secondMarkertmp.touchHandler = { [weak self] (overlay: NMFOverlay) -> Bool in
if self?.selectedMarker == nil { /// ν΄λ¦­ν–ˆλ˜ ν˜„μƒμ†Œκ°€ μ—†λŠ” 경우 (지도뷰 처음 λ“€μ–΄μ˜¬ λ–„)
self?.selectedMarker = secondMarkertmp
self?.selectedMarker?.iconImage = NMFOverlayImage(image: Asset.icnStudioSelected.image)
self?.showBottomSheet()
} else {
self?.clickCount = 1
markertmp.iconImage = NMFOverlayImage(image: Asset.icnStudioSelected.image)
if self?.selectedMarker == secondMarkertmp { /// ν΄λ¦­ν–ˆλ˜ ν˜„μƒμ†Œλ₯Ό λ‹€μ‹œ ν΄λ¦­ν•˜λŠ” 경우
self?.selectedMarker?.iconImage = NMFOverlayImage(image: Asset.icnStudio.image)
self?.hideBottomSheetAndGoBack()
} else { /// λ‹€λ₯Έ ν˜„μƒμ†Œ 클릭
self?.selectedMarker?.iconImage = NMFOverlayImage(image: Asset.icnStudio.image)
self?.selectedMarker = secondMarkertmp
self?.selectedMarker?.iconImage = NMFOverlayImage(image: Asset.icnStudioSelected.image)
self?.showBottomSheet()
}
}
return true
}

markertmp.touchHandler = { [weak self] (overlay: NMFOverlay) -> Bool in
if self?.selectedMarker == nil { /// ν΄λ¦­ν–ˆλ˜ ν˜„μƒμ†Œκ°€ μ—†λŠ” 경우 (지도뷰 처음 λ“€μ–΄μ˜¬ λ–„)
self?.selectedMarker = markertmp
self?.selectedMarker?.iconImage = NMFOverlayImage(image: Asset.icnStudioSelected.image)
self?.showBottomSheet()
} else {
if self?.selectedMarker == markertmp { /// ν΄λ¦­ν–ˆλ˜ ν˜„μƒμ†Œλ₯Ό λ‹€μ‹œ ν΄λ¦­ν•˜λŠ” 경우
self?.selectedMarker?.iconImage = NMFOverlayImage(image: Asset.icnStudio.image)
self?.selectedMarker = nil
self?.hideBottomSheetAndGoBack()
} else { /// λ‹€λ₯Έ ν˜„μƒμ†Œ 클릭
self?.selectedMarker?.iconImage = NMFOverlayImage(image: Asset.icnStudio.image)
self?.selectedMarker = markertmp
self?.selectedMarker?.iconImage = NMFOverlayImage(image: Asset.icnStudioSelected.image)
self?.showBottomSheet()
}
}
return true
}
}

private func setUpMapView() {
view.addSubview(mapView)
let locationOverlay = mapView.mapView.locationOverlay
Expand All @@ -157,16 +182,26 @@ extension StudioMapViewController {
marker.iconImage = NMFOverlayImage(image: Asset.icnStudio.image)

marker.touchHandler = { [weak self] (overlay: NMFOverlay) -> Bool in
if self?.clickCount == 1 { /// 이미 λ§ˆμ»€κ°€ 클릭된 경우 (쀑볡 클릭 ν—ˆμš©μ•ˆν•¨)
self?.clickCount = 0
self?.hideBottomSheetAndGoBack()
marker.iconImage = NMFOverlayImage(image: Asset.icnStudio.image)
} else {
self?.clickCount = 1
if self?.selectedMarker == nil { /// ν΄λ¦­ν–ˆλ˜ ν˜„μƒμ†Œκ°€ μ—†λŠ” 경우 (지도뷰 처음 λ“€μ–΄μ˜¬ λ–„)
self?.selectedMarker = marker
self?.selectedMarker?.iconImage = NMFOverlayImage(image: Asset.icnStudioSelected.image)
self?.showBottomSheet()
self?.selectedMarkerInfo = markerInfo
StudioMapViewController.selectedMarkerID = markerInfo.id
self?.studioInfoWithAPI(studioID: markerInfo.id)
// TODO: - 카메라 이동 (톡신 ν•„μš”)
} else {
if self?.selectedMarker == marker { /// ν΄λ¦­ν–ˆλ˜ ν˜„μƒμ†Œλ₯Ό λ‹€μ‹œ ν΄λ¦­ν•˜λŠ” 경우
self?.selectedMarker?.iconImage = NMFOverlayImage(image: Asset.icnStudio.image)
self?.selectedMarker = nil
self?.hideBottomSheetAndGoBack()
} else { /// λ‹€λ₯Έ ν˜„μƒμ†Œ 클릭
self?.selectedMarker?.iconImage = NMFOverlayImage(image: Asset.icnStudio.image)
self?.selectedMarker = marker
self?.selectedMarker?.iconImage = NMFOverlayImage(image: Asset.icnStudioSelected.image)
self?.showBottomSheet()
// TODO: - 카메라 이동 (톡신 ν•„μš”)
}
}
return true
}
Expand All @@ -177,9 +212,9 @@ extension StudioMapViewController {
func getBottomSheetInfo() {
StudioMapViewController.name = "ν•„λ¦° ν˜„μƒμ†Œ"
StudioMapViewController.address = "μ†νŠΈμ‹œ μ•±μžΌκ΅¬ 필린동 μ•„μš”λ‘œ 12번길 13"
StudioMapViewController.time = "open 10:00-21:00"
StudioMapViewController.time = "open 00:00-24:00"
StudioMapViewController.tel = "010-1234-5678"
StudioMapViewController.price = "컬러 5000원"
StudioMapViewController.price = "컬러 5000000000원"
StudioMapViewController.site = ""

// StudioMapViewController.name = self.serverStudioInfo?.studio.name
Expand Down Expand Up @@ -264,12 +299,6 @@ extension StudioMapViewController {
newVC.modalPresentationStyle = .fullScreen
self.present(newVC, animated: true, completion: nil)
}

@objc func changeMarkerObserver(_ notification: Notification) {
selectedMarker?.iconImage = NMFOverlayImage(image: Asset.icnPlaceBig.image)
selectedMarker = nil
clickCount = 0
}

@objc func touchLocationButton(_ sender: UIButton) {
sender.isSelected = !sender.isSelected
Expand Down Expand Up @@ -444,6 +473,8 @@ extension StudioMapViewController {
func hideBottomSheetAndGoBack() {
let safeAreaHeight = view.safeAreaLayoutGuide.layoutFrame.height
let bottomPadding = view.safeAreaInsets.bottom
self.selectedMarker?.iconImage = NMFOverlayImage(image: Asset.icnStudio.image)
self.selectedMarker = nil
bottomSheetViewTopConstraint.constant = safeAreaHeight + bottomPadding
UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseOut, animations: {
self.view.layoutIfNeeded()
Expand All @@ -455,10 +486,6 @@ extension StudioMapViewController {
else { return number }
return nearestVal
}

func setNotification() {
NotificationCenter.default.post(name: NSNotification.Name.changeMarker, object: nil, userInfo: nil)
}

func changeScrollEnabled() {
let contentVC = children.first as? StudioMapContentViewController
Expand Down Expand Up @@ -495,7 +522,6 @@ extension StudioMapViewController {
}
case .ended:
if velocity.y > 1500 {
setNotification()
hideBottomSheetAndGoBack()
return
}
Expand All @@ -508,7 +534,6 @@ extension StudioMapViewController {
} else if nearestValue == defaultPadding {
showBottomSheet(atState: .normal)
} else {
setNotification()
hideBottomSheetAndGoBack()
}
default:
Expand Down

0 comments on commit 914c13e

Please sign in to comment.