Skip to content

Commit

Permalink
Feat: Implement TickMarkSlider Delegate #89
Browse files Browse the repository at this point in the history
- Implement TickMarkSlider to track current value of the Slider
- Set navigation button of LocationVC to indicate current distance value of slider
  • Loading branch information
jinios committed Jul 22, 2019
1 parent 77c11cf commit 6891c7b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 56 deletions.
4 changes: 4 additions & 0 deletions MartHoliday/MartHoliday.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -254,6 +255,7 @@
FDF8ABC3215B76B400DA74C9 /* MainTableViewHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTableViewHeader.swift; sourceTree = "<group>"; };
FDF8ABC5215B76FC00DA74C9 /* MainTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTableViewCell.swift; sourceTree = "<group>"; };
FDFB0344212E7AF10092411E /* MartHoliday.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MartHoliday.entitlements; sourceTree = "<group>"; };
FDFF1CD422E455520045220F /* TickMarkSlider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TickMarkSlider.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -331,6 +333,7 @@
FD5359FD225F8BDB00AB48BE /* MartMapView.swift */,
FDF492C822B4E59C00827025 /* MarkerInfoWindowView.swift */,
FDF492C622B4E59100827025 /* MarkerInfoWindowView.xib */,
FDFF1CD422E455520045220F /* TickMarkSlider.swift */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
58 changes: 12 additions & 46 deletions MartHoliday/MartHoliday/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -489,35 +489,15 @@ Cgo
<userDefinedRuntimeAttribute type="boolean" keyPath="showLocationButton" value="YES"/>
</userDefinedRuntimeAttributes>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="PQR-co-5qa">
<rect key="frame" x="0.0" y="44" width="375" height="45"/>
<subviews>
<segmentedControl opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="MVv-RV-Hy0">
<rect key="frame" x="30" y="8.6666666666666643" width="315" height="29"/>
<color key="backgroundColor" name="mh-mint"/>
<segments>
<segment title="2km"/>
<segment title="5km"/>
<segment title="7km"/>
</segments>
<color key="tintColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<connections>
<action selector="distanceSegmentedControlChanged:" destination="0c7-x9-EAa" eventType="valueChanged" id="yjC-AR-sdh"/>
</connections>
</segmentedControl>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="tintColor" name="mh-lightgray"/>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="X6j-SK-HJD">
<rect key="frame" x="0.0" y="44" width="375" height="52"/>
<color key="backgroundColor" name="mh-yellow"/>
<constraints>
<constraint firstItem="MVv-RV-Hy0" firstAttribute="leading" secondItem="PQR-co-5qa" secondAttribute="leading" constant="30" id="0yO-eO-9xV"/>
<constraint firstAttribute="trailing" secondItem="MVv-RV-Hy0" secondAttribute="trailing" constant="30" id="Ugs-h6-Wjv"/>
<constraint firstItem="MVv-RV-Hy0" firstAttribute="centerY" secondItem="PQR-co-5qa" secondAttribute="centerY" id="iEu-D9-h2Y"/>
<constraint firstAttribute="height" constant="45" id="pB2-6J-c00"/>
<constraint firstItem="MVv-RV-Hy0" firstAttribute="centerX" secondItem="PQR-co-5qa" secondAttribute="centerX" id="qZ2-QA-ero"/>
<constraint firstAttribute="height" constant="52" id="EB3-ks-jlP"/>
</constraints>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ATF-n8-0BF">
<rect key="frame" x="122.66666666666669" y="94" width="130" height="37"/>
<rect key="frame" x="122.66666666666669" y="344" width="130" height="37"/>
<color key="backgroundColor" name="mh-mint"/>
<constraints>
<constraint firstAttribute="height" constant="37" id="Vii-jo-uR4"/>
Expand All @@ -531,39 +511,31 @@ Cgo
<action selector="searchAgainButtonTapped:" destination="0c7-x9-EAa" eventType="touchUpInside" id="ivy-89-Ob6"/>
</connections>
</button>
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="3.5" translatesAutoresizingMaskIntoConstraints="NO" id="1Hl-cV-cV2">
<rect key="frame" x="98" y="181" width="179" height="31"/>
<color key="minimumTrackTintColor" name="mh-red"/>
<color key="maximumTrackTintColor" name="mh-navy"/>
<color key="thumbTintColor" name="mh-yellow"/>
</slider>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="ATF-n8-0BF" firstAttribute="top" secondItem="eFQ-Aq-t96" secondAttribute="top" constant="50" id="1ff-wP-iNq"/>
<constraint firstItem="ATF-n8-0BF" firstAttribute="top" secondItem="eFQ-Aq-t96" secondAttribute="top" constant="300" id="1ff-wP-iNq"/>
<constraint firstAttribute="bottom" secondItem="VUR-Wx-Vkf" secondAttribute="bottom" id="3Aj-Jn-s9d"/>
<constraint firstItem="eFQ-Aq-t96" firstAttribute="trailing" secondItem="1Hl-cV-cV2" secondAttribute="trailing" constant="100" id="3sX-Bf-cHZ"/>
<constraint firstItem="PQR-co-5qa" firstAttribute="leading" secondItem="eFQ-Aq-t96" secondAttribute="leading" id="GwZ-RL-gA2"/>
<constraint firstItem="X6j-SK-HJD" firstAttribute="leading" secondItem="eFQ-Aq-t96" secondAttribute="leading" id="4iv-Bw-Kfd"/>
<constraint firstItem="eFQ-Aq-t96" firstAttribute="trailing" secondItem="VUR-Wx-Vkf" secondAttribute="trailing" id="Jvf-p8-gML"/>
<constraint firstItem="ATF-n8-0BF" firstAttribute="centerX" secondItem="iGd-SD-Jr7" secondAttribute="centerX" id="MXh-id-vgf"/>
<constraint firstItem="1Hl-cV-cV2" firstAttribute="leading" secondItem="eFQ-Aq-t96" secondAttribute="leading" constant="100" id="McS-Sg-C4g"/>
<constraint firstItem="PQR-co-5qa" firstAttribute="top" secondItem="eFQ-Aq-t96" secondAttribute="top" id="NVn-fy-rkB"/>
<constraint firstItem="VUR-Wx-Vkf" firstAttribute="leading" secondItem="eFQ-Aq-t96" secondAttribute="leading" id="P3P-2W-TEY"/>
<constraint firstItem="PQR-co-5qa" firstAttribute="trailing" secondItem="eFQ-Aq-t96" secondAttribute="trailing" id="WRa-Si-LgA"/>
<constraint firstItem="1Hl-cV-cV2" firstAttribute="top" secondItem="ATF-n8-0BF" secondAttribute="bottom" constant="50" id="hVm-d9-N5Q"/>
<constraint firstItem="X6j-SK-HJD" firstAttribute="trailing" secondItem="eFQ-Aq-t96" secondAttribute="trailing" id="hJJ-2U-sip"/>
<constraint firstItem="X6j-SK-HJD" firstAttribute="top" secondItem="eFQ-Aq-t96" secondAttribute="top" id="iAu-98-sgI"/>
<constraint firstItem="VUR-Wx-Vkf" firstAttribute="top" secondItem="eFQ-Aq-t96" secondAttribute="top" id="kgW-ms-DLN"/>
</constraints>
<viewLayoutGuide key="safeArea" id="eFQ-Aq-t96"/>
</view>
<connections>
<outlet property="distanceSlider" destination="1Hl-cV-cV2" id="Z3B-np-GKl"/>
<outlet property="naverMapView" destination="VUR-Wx-Vkf" id="XiJ-hg-yky"/>
<outlet property="searchAgainButton" destination="ATF-n8-0BF" id="h1c-ke-n2s"/>
<outlet property="sliderView" destination="X6j-SK-HJD" id="Pur-hg-0VG"/>
<outlet property="sliderViewTopConstraint" destination="iAu-98-sgI" id="qk5-Pl-Gey"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="z1Q-hG-VW4" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1637.5999999999999" y="146.17691154422789"/>
<point key="canvasLocation" x="1637.5999999999999" y="145.56650246305421"/>
</scene>
<!--Main View Controller-->
<scene sceneID="27w-gz-Gyf">
Expand Down Expand Up @@ -653,12 +625,6 @@ Cgo
<namedColor name="mh-mint">
<color red="0.54117647058823526" green="0.7686274509803922" blue="0.81568627450980391" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
</namedColor>
<namedColor name="mh-navy">
<color red="0.15686274509803921" green="0.32156862745098042" blue="0.47843137254901963" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<namedColor name="mh-red">
<color red="0.92156862745098034" green="0.31764705882352939" blue="0.30980392156862746" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<namedColor name="mh-yellow">
<color red="1" green="0.93333333333333335" blue="0.41568627450980394" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
Expand Down
16 changes: 12 additions & 4 deletions MartHoliday/MartHoliday/View/TickMarkSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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()
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -37,6 +38,8 @@ class LocationSearchViewController: IndicatorViewController, NMFMapViewDelegate
}
}

var distanceSlider: TickMarkSlider?

var previousUserLocation: NMGLatLng?

var searchDistance: SearchDistance?
Expand All @@ -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)
Expand All @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -210,6 +219,11 @@ extension LocationSearchViewController {
})
}

// MARK: - TickMarkSlider Delegate

func valueChanged(_ sender: UISlider) {
self.settingDistance = Int(distanceSlider!.value)
}

// MARK: - MapView Delegate

Expand Down

0 comments on commit 6891c7b

Please sign in to comment.