Ian*_*ink 5 iphone mkmapview uigesturerecognizer ios
我试图检测MKMapVIew上的水龙头的位置,以便在该位置放置一个引脚.是否有我可以捕获的事件会给我这些信息?
以下是在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;
        }
    }
| 归档时间: | 
 | 
| 查看次数: | 6586 次 | 
| 最近记录: |