Yano's answer worked for me, so I decided to leave an updated version for Swift 4 / XCode 9, since I am not very good at Objective-C and I am sure that there are others that are not.
Step 1: Add this code to viewDidLoad:
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(didDragMap(_:))) panGesture.delegate = self
Step 2. Verify that your class matches UIGestureRecognizerDelegate:
class MapViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate, UIGestureRecognizerDelegate {
Step 3: Add the following function to make your panGesture work simultaneously with other gestures:
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { return true }
Step 4. And make sure that your method is not called “50 times per drag”, as Jano rightly notes:
@objc func didDragMap(_ gestureRecognizer: UIPanGestureRecognizer) { if (gestureRecognizer.state == UIGestureRecognizerState.ended) { redoSearchButton.isHidden = false resetLocationButton.isHidden = false } }
* Note the addition of @objc in the last step. Xcode forcibly uses this prefix for your function to compile it.
Pigpocket Feb 08 '18 at 2:29 2018-02-08 02:29
source share