我正在使用Xmarin創建具有自定義註釋的地圖,並且出於某種原因,一旦我點擊註釋,就不會調用DidSelectAnnotationView方法。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;
}
什麼想法?
什麼是'_idToAnotations'?向'viewAnnotation'添加'view'之後,嘗試設置'viewAnnotation.frame'等於'view.frame'。作爲單獨的測試,請嘗試完全註釋GetViewForAnnotation方法,以便地圖視圖創建默認的紅色視圖視圖,然後查看是否會調用DidSelectAnnotationView方法。 – Anna