下面的代码似乎打印了两次值,即使我按住2秒。
不管我换成什么样的持续时间,似乎总是要执行两次,有人知道为什么会这样吗?
func action(gestureRecognizer:UIGestureRecognizer){
var touchPoint = gestureRecognizer.locationInView(self.myMap);
var newCo = myMap.convertPoint(touchPoint, toCoordinateFromView: self.myMap);
var annotation = MKPointAnnotation();
annotation.coordinate = newCo;
var loc = CLLocation(latitude: newCo.latitude, longitude: newCo.longitude);
CLGeocoder().reverseGeocodeLocation(loc, completionHandler: {(placemarks, error)->Void in
let pm:CLPlacemark = placemarks[0] as CLPlacemark;
var address = pm.locality + " ," + pm.postalCode + " ," + pm.administrativeArea + " ," + pm.country;
annotation.title = address;
self.myMap.addAnnotation(annotation);
println(address);
println("\(newCo.latitude)");
println("\(newCo.longitude)");
//places.append(["name:":address, "lat": "\(newCo.latitude)", "lon":"\(newCo.longitude)"]);
})
}
最佳答案
检查UIGestureRecognizer的state属性,可能会同时得到begin和end。
enum UIGestureRecognizerState : Int {
case Possible
case Began
case Changed
case Ended
case Cancelled
case Failed
}