2015-07-20 43 views
1

我有以下代碼,沒有錯誤,當我運行這個。長按工作正常,雙擊不工作。在添加雙擊手勢之前,我已經禁用了縮放。Xcode7 swift2 - 雙擊MKMapView不起作用

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 

    manager = CLLocationManager() 
    manager.delegate = self 
    manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation 
    manager.requestWhenInUseAuthorization() 
    manager.startUpdatingLocation() 
    routeMapView.zoomEnabled = false 
    routeMapView.showsPointsOfInterest = true 

    let doubleTapGesture = UITapGestureRecognizer(target: self, action: "routeMapDoubleTapSelector:") 
    doubleTapGesture.numberOfTapsRequired = 2 
    routeMapView.addGestureRecognizer(doubleTapGesture) 

    let ulpgr = UILongPressGestureRecognizer(target: self, action:"routeMapLongPressSelector:") 
    ulpgr.minimumPressDuration = 2.0 
    routeMapView.addGestureRecognizer(ulpgr) 


} 

任何幫助?

回答

1

我試過你的代碼,它似乎工作正常。打印「雙擊」。這是測試代碼。

import UIKit 
import MapKit 

class ViewController: UIViewController, CLLocationManagerDelegate { 

let manager = CLLocationManager() 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 

    manager.delegate = self 
    manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation 
    manager.requestWhenInUseAuthorization() 
    manager.startUpdatingLocation() 

    let routeMapView = MKMapView() 
    self.view = routeMapView 

    routeMapView.zoomEnabled = false 
    routeMapView.showsPointsOfInterest = true 

    let doubleTapGesture = UITapGestureRecognizer(target: self, action: "routeMapDoubleTapSelector:") 
    doubleTapGesture.numberOfTapsRequired = 2 
    routeMapView.addGestureRecognizer(doubleTapGesture) 

    let ulpgr = UILongPressGestureRecognizer(target: self, action:"routeMapLongPressSelector:") 
    ulpgr.minimumPressDuration = 2.0 
    routeMapView.addGestureRecognizer(ulpgr) 
} 

func routeMapDoubleTapSelector(sender: AnyObject) { 
    NSLog("double taps") 
} 

func routeMapLongPressSelector(sender: AnyObject) { 
    NSLog("long press") 
} 
} 
+0

它現在有效。我在doubleTap選擇器方法中刪除了「if gestureRecognizer.state」條件。感謝您的幫助。 – sfbayman