0

Trying to work out how to detect a touch gesture in a mapView in swift. I reload the mapView when there has been movement but I want to disable this for 15 seconds if the user is touching/interacting with the map

Thoughts

NicB72
  • 21
  • 4

1 Answers1

1

Solved it. Putting this out for others. I use the boolReloadMapAllowed in my other map drawing functions. In this case it won't reload while the user is moving it and waits until 7 seconds after moving has ended before it reloads the map.

Thanks to https://stackoverflow.com/users/4253437/codebender whose post really helped. determine if MKMapView was dragged/moved

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
    super.touchesMoved(touches, with: event)
    boolReloadMapAllowed = false
    print("Something moved")
          if !(self.tmrMapMove.isValid) {
              let mapMoveSelector : Selector = #selector(vwMain.mapMoveOver)
               self.tmrMapMove = Timer.scheduledTimer(timeInterval: 7, target:self, selector: mapMoveSelector, userInfo: nil, repeats: true)
           }
}

@objc func mapMoveOver() {
    boolReloadMapAllowed = true
}
NicB72
  • 21
  • 4