gpt4 book ai didi

iphone - MKMapVIew - 在点击点放置 Pin

转载 作者:可可西里 更新时间:2023-11-01 04:28:05 27 4
gpt4 key购买 nike

我正在尝试检测 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;
}
}

关于iphone - MKMapVIew - 在点击点放置 Pin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7728654/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com