我正在尝试检测MKMapVIew上水龙头的位置,以便在该位置放置一个针脚。是否有我可以捕获的事件会给我这些信息?
答案 0 :(得分:8)
以下是在C#中翻译成MonoTouch的答案
将其添加到持有MKMapView的ViewController
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
UILongPressGestureRecognizer sgr = new UILongPressGestureRecognizer ();
sgr.AddTarget (this, new MonoTouch.ObjCRuntime.Selector ("LongPressGesture"));
sgr.MinimumPressDuration = 1f;
sgr.Delegate = new LongPressRecognizerDelegate ();
this.View.AddGestureRecognizer (sgr);
}
[Export("LongPressGesture")]
public void Handle (UIGestureRecognizer recognizer)
{
//http://freshmob.com.au/mapkit/mapkit-tap-and-hold-to-drop-a-pin-on-the-map/
//and
//http://inxunxa.wordpress.com/2011/03/10/monotouch-longpress/
if (recognizer.State != UIGestureRecognizerState.Began)
return;
// get the point of the action
PointF point = recognizer.LocationInView (this.View);
CLLocationCoordinate2D coord = this.map.ConvertPoint (point, this.map);
//Add pin annoation here
LocationAnnotation ann = new LocationAnnotation (new LocationEntity (coord));
this.map.AddAnnotation (ann);
}
public class LongPressRecognizerDelegate : MonoTouch.UIKit.UIGestureRecognizerDelegate
{
public override bool ShouldReceiveTouch (UIGestureRecognizer recognizer, UITouch touch)
{
return true;
}
}
答案 1 :(得分:7)