【问题标题】:MKMapVIew - Place Pin at tap pointMKMapVIew - 在点击点放置引脚
【发布时间】:2011-12-05 10:22:23
【问题描述】:

我正在尝试检测 MKMapVIew 上的点击位置,以便在该位置放置一个图钉。有没有我可以捕捉到的事件会给我这些信息?

【问题讨论】:

    标签: iphone ios mkmapview uigesturerecognizer


    【解决方案1】:

    这是用 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;
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-23
      • 2018-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多