我正在使用Xmarin创建一个带有自定义注释的地图,但由于某些原因,一旦我点击注释,就不会调用DidSelectAnnotationView方法。
下面是我是如何创建注释的:
public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, MonoTouch.Foundation.NSObject annotation)
{
var item = annotation as MKPointAnnotation;
if (item == null)
{
return null;
}
if (_idToAnotations.ContainsKey (item.Title))
{
return _idToAnotations [item.Title];
}
UIView view = null;
MKAnnotationView viewAnnotation = new MKAnnotationView ();
Branch branch = _displayedBranches [item.Title];
view = CreateMapAnnotation (branch.Name);
viewAnnotation.Add (view);
viewAnnotation.CanShowCallout = false;
return viewAnnotation;
}
下面是我如何创建要放在MKAnnotationView中的视图:
static UIView CreateMapAnnotation (string title)
{
UIView view = new UIView (new RectangleF (0, 0, 60, 68));
UILabel text = new UILabel (new RectangleF (1, 0, 60, 15));
text.Text = title;
text.Font = text.Font.WithSize (12f);
text.TextColor = UIColor.White;
text.BackgroundColor = UIColor.Black;
text.Layer.CornerRadius = 6;
text.TextAlignment = UITextAlignment.Center;
view.Add (text);
UIImageView image = new UIImageView (new RectangleF (0, 17, 60, 40));
image.Image = new UIImage ("map_pin_red.png");
view.Add (image);
return view;
}
有什么想法吗?
发布于 2014-01-23 22:06:02
我believe指出,只有在MKAnnotationViews的Title
属性值和CanShowCallout
= true的情况下,才会调用CanShowCallout
。如果您不能进行这些更改,那么您可能需要实现自己的tap事件处理程序。
还有什么原因你没有使用正确的MKAnnotationView构造函数和注解对象和重用标识符,以及调用DequeueReusableAnnotation方法(请参阅Xamarin docs)?这是大多数使用注释视图的最佳实践。
发布于 2016-01-06 19:55:22
您必须通过调用以下方法取消选择单击的注释
func mapView(_ mapView: MKMapView, didDeselectAnnotationView view: MKAnnotationView)
以便在下一次单击时可以访问它。
https://stackoverflow.com/questions/21263299
复制相似问题