WhirlyGlobe
WhirlyGlobe copied to clipboard
[iOS]How can I stop moving the map immediately after I stop gesturing?
RT
I fixed this by:
- adding a UIPanGestureRecognizer to my WhirlyGlobeViewController's view
- adding a MaplyCoordinate var that is used to keep track of where the user's gesture ends - I called this
forcedCenter
- the action of the UIPanGestureRecogniser checks the velocity when the gesture ends, and if it's less than 50px/second it sets
forcedCenter
. Code if it helps:
@IBAction func didPan(_ sender: Any) {
if self.panGestureRecognizer.state == .ended {
let velocity = self.panGestureRecognizer.velocity(in: self.globe.view)
guard abs(velocity.x) < 50 && abs(velocity.y) < 50 else { return }
self.forcedCenter = self.globe.getPosition()
}
}
- globeViewController(_:, didMove:) keeps firing, but it's suppressed like so:
func globeViewController(_ viewC: WhirlyGlobeViewController, didMove corners: UnsafeMutablePointer<MaplyCoordinate>) {
if let forcedCenter = self.forcedCenter {
viewC.setPosition(forcedCenter)
}
}
- finally, clear out
forcedCenter
when the globe eventually stops moving:
func globeViewController(_ viewC: WhirlyGlobeViewController, didStopMoving corners: UnsafeMutablePointer<MaplyCoordinate>, userMotion: Bool) {
self.forcedCenter = nil
}
Nice!