diff --git a/MartHoliday/MartHoliday.xcodeproj/project.pbxproj b/MartHoliday/MartHoliday.xcodeproj/project.pbxproj index ae64de7..3b5e3c4 100644 --- a/MartHoliday/MartHoliday.xcodeproj/project.pbxproj +++ b/MartHoliday/MartHoliday.xcodeproj/project.pbxproj @@ -111,6 +111,7 @@ FDF8ABC2215B722800DA74C9 /* FavoriteBranch.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDF8ABC1215B722800DA74C9 /* FavoriteBranch.swift */; }; FDF8ABC4215B76B400DA74C9 /* MainTableViewHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDF8ABC3215B76B400DA74C9 /* MainTableViewHeader.swift */; }; FDF8ABC6215B76FC00DA74C9 /* MainTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDF8ABC5215B76FC00DA74C9 /* MainTableViewCell.swift */; }; + FDFF1CD522E455520045220F /* TickMarkSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDFF1CD422E455520045220F /* TickMarkSlider.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -254,6 +255,7 @@ FDF8ABC3215B76B400DA74C9 /* MainTableViewHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTableViewHeader.swift; sourceTree = ""; }; FDF8ABC5215B76FC00DA74C9 /* MainTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTableViewCell.swift; sourceTree = ""; }; FDFB0344212E7AF10092411E /* MartHoliday.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MartHoliday.entitlements; sourceTree = ""; }; + FDFF1CD422E455520045220F /* TickMarkSlider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TickMarkSlider.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -331,6 +333,7 @@ FD5359FD225F8BDB00AB48BE /* MartMapView.swift */, FDF492C822B4E59C00827025 /* MarkerInfoWindowView.swift */, FDF492C622B4E59100827025 /* MarkerInfoWindowView.xib */, + FDFF1CD422E455520045220F /* TickMarkSlider.swift */, ); path = View; sourceTree = ""; @@ -806,6 +809,7 @@ FD5359FE225F8BDB00AB48BE /* MartMapView.swift in Sources */, FD9F409C211EBFAF007D7F1B /* BranchRawData.swift in Sources */, FDC5A7422167CD50009F0B0C /* TodayExtensionTableViewCell.swift in Sources */, + FDFF1CD522E455520045220F /* TickMarkSlider.swift in Sources */, FDF8ABC6215B76FC00DA74C9 /* MainTableViewCell.swift in Sources */, FDB3AD67216F94FD002209A2 /* StorageAPI.swift in Sources */, FD91364E216EF70B001A21DF /* AppInfoViewController.swift in Sources */, diff --git a/MartHoliday/MartHoliday/Base.lproj/Main.storyboard b/MartHoliday/MartHoliday/Base.lproj/Main.storyboard index 64573b6..f5a489e 100644 --- a/MartHoliday/MartHoliday/Base.lproj/Main.storyboard +++ b/MartHoliday/MartHoliday/Base.lproj/Main.storyboard @@ -489,35 +489,15 @@ Cgo - - - - - - - - - - - - - - - - - - - + + + - - - - - + - - - - - - - + - - + - - - - + + - + + - + @@ -653,12 +625,6 @@ Cgo - - - - - - diff --git a/MartHoliday/MartHoliday/View/TickMarkSlider.swift b/MartHoliday/MartHoliday/View/TickMarkSlider.swift index e2faca8..fe53451 100644 --- a/MartHoliday/MartHoliday/View/TickMarkSlider.swift +++ b/MartHoliday/MartHoliday/View/TickMarkSlider.swift @@ -8,21 +8,27 @@ import UIKit +protocol TickMarkSliderDelegate { + func valueChanged(_ sender: UISlider) +} + class TickMarkSlider: UISlider { var numberOfTickMarks: Float? var unit: Float? + var delegate: TickMarkSliderDelegate? - let hapticGenerator = UIImpactFeedbackGenerator(style: .light) + private let hapticGenerator = UIImpactFeedbackGenerator(style: .light) - convenience init(tick: Float, maximumValue: Float, frame: CGRect) { + convenience init(tick: Float, maximumValue: Float, initialValue: Float, frame: CGRect) { self.init(frame: frame) self.numberOfTickMarks = tick - self.maximumValue = maximumValue self.unit = (maximumValue - self.minimumValue) / tick + self.maximumValue = maximumValue + self.value = initialValue } - override init(frame: CGRect) { + private override init(frame: CGRect) { super.init(frame: frame) } @@ -58,8 +64,10 @@ class TickMarkSlider: UISlider { guard let unit = self.unit else { return } let newStep = roundf(self.value / unit) self.value = newStep * unit + self.delegate?.valueChanged(self) hapticGenerator.impactOccurred() } + } diff --git a/MartHoliday/MartHoliday/ViewController/LocationSearchViewController.swift b/MartHoliday/MartHoliday/ViewController/LocationSearchViewController.swift index 14dfb10..b51a143 100644 --- a/MartHoliday/MartHoliday/ViewController/LocationSearchViewController.swift +++ b/MartHoliday/MartHoliday/ViewController/LocationSearchViewController.swift @@ -21,11 +21,12 @@ enum SearchDistance: Int { } -class LocationSearchViewController: IndicatorViewController, NMFMapViewDelegate { +class LocationSearchViewController: IndicatorViewController, NMFMapViewDelegate, TickMarkSliderDelegate { @IBOutlet weak var naverMapView: NMFNaverMapView! @IBOutlet weak var searchAgainButton: UIButton! - @IBOutlet weak var distanceSlider: UISlider! + @IBOutlet weak var sliderView : UIView! + @IBOutlet weak var sliderViewTopConstraint: NSLayoutConstraint! var userLocation: NMGLatLng? { didSet { @@ -37,6 +38,8 @@ class LocationSearchViewController: IndicatorViewController, NMFMapViewDelegate } } + var distanceSlider: TickMarkSlider? + var previousUserLocation: NMGLatLng? var searchDistance: SearchDistance? @@ -54,7 +57,6 @@ class LocationSearchViewController: IndicatorViewController, NMFMapViewDelegate self.searchAgainButton.alpha = 0 self.userLocation = self.locationOverlay?.location naverMapView.delegate = self - self.settingDistance = 3 naverMapView.addObserver(self, forKeyPath: "positionMode", options: [.new], context: nil) NotificationCenter.default.addObserver(self, selector: #selector(showErrorAlert), name: .apiErrorAlertPopup, object: nil) @@ -79,6 +81,13 @@ class LocationSearchViewController: IndicatorViewController, NMFMapViewDelegate self.finishIndicator() } + distanceSlider = TickMarkSlider(tick: 8, maximumValue: 8, initialValue: 2.0, frame: self.sliderView.bounds) + distanceSlider!.addTickMarks() + distanceSlider!.delegate = self + self.sliderView.addSubview(distanceSlider!) + + self.settingDistance = Int(distanceSlider!.value) + } @objc private func showErrorAlert() { @@ -118,12 +127,12 @@ class LocationSearchViewController: IndicatorViewController, NMFMapViewDelegate distanceSettingButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: -4, bottom: 0, right: 0) distanceSettingButton.titleEdgeInsets = UIEdgeInsets(top: 2, left: 2, bottom: 0, right: 0) distanceSettingButton.layer.borderColor = UIColor.white.cgColor - distanceSettingButton.layer.borderWidth = 0.5 - distanceSettingButton.layer.cornerRadius = 8.0 + distanceSettingButton.layer.borderWidth = 1.0 + distanceSettingButton.layer.cornerRadius = 13.0 distanceSettingButton.clipsToBounds = true distanceSettingButton.addTarget(self, action: #selector(changeSearchDistance), for: .touchUpInside) - distanceSettingButton.frame = CGRect(x: 0, y: 0, width: 62, height: 28) + distanceSettingButton.frame = CGRect(x: 0, y: 0, width: 68, height: 30) let homeBarButton = UIBarButtonItem(customView: distanceSettingButton) self.navigationItem.setRightBarButtonItems([homeBarButton], animated: false) @@ -210,6 +219,11 @@ extension LocationSearchViewController { }) } + // MARK: - TickMarkSlider Delegate + + func valueChanged(_ sender: UISlider) { + self.settingDistance = Int(distanceSlider!.value) + } // MARK: - MapView Delegate