Xamarin.ios Xamarin Forms 4.1 CalloutAccessoryControlTapped不再为tap on annotation视图调用

Xamarin.ios Xamarin Forms 4.1 CalloutAccessoryControlTapped不再为tap on annotation视图调用,xamarin.ios,xamarin.forms.maps,Xamarin.ios,Xamarin.forms.maps,最近,iOS地图批注中的一个行为发生了更改: 当用户点击注释视图时,不再调用Callout AccessoryControlTapped事件。例如,如果我点击上图中的红色区域。触发事件的唯一方法是点击右侧的信息按钮 当我们点击注释的整个表面时,是否有办法强制提升Callout AccessoryControlTapped protected override void OnElementChanged(ElementChangedEventArgs<View> e)

最近,iOS地图批注中的一个行为发生了更改:

当用户点击注释视图时,不再调用Callout AccessoryControlTapped事件。例如,如果我点击上图中的红色区域。触发事件的唯一方法是点击右侧的信息按钮

当我们点击注释的整个表面时,是否有办法强制提升
Callout AccessoryControlTapped

protected override void OnElementChanged(ElementChangedEventArgs<View> e)
        {
            base.OnElementChanged(e);

            if (Control is MKMapView nativeMap)
            {
                if (e.OldElement != null)
                {
                    nativeMap.RemoveAnnotations(nativeMap.Annotations);
                    nativeMap.GetViewForAnnotation = null;
                    nativeMap.CalloutAccessoryControlTapped -= OnCalloutAccessoryControlTapped;
                }

                if (e.NewElement != null)
                {
                    CustomMap = (CustomMap)e.NewElement;

                    nativeMap.GetViewForAnnotation = GetViewForAnnotation;
                    nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped;
                }
            }
        }

// event delegate
private void OnCalloutAccessoryControlTapped(object sender, MKMapViewAccessoryTappedEventArgs e)
    {
        // ...
    }
protected override void OnElementChanged(ElementChangedEventArgs e)
{
基础。一个要素发生变化(e);
if(控件为MKMapView nativeMap)
{
if(e.OldElement!=null)
{
nativeMap.RemoveAnnotations(nativeMap.Annotations);
nativeMap.GetViewForAnnotation=null;
nativeMap.CalloutAccessoryControlTapped-=OnCalloutAccessoryControlTapped;
}
if(例如NewElement!=null)
{
CustomMap=(CustomMap)e.NewElement;
nativeMap.GetViewForAnnotation=GetViewForAnnotation;
nativeMap.CalloutAccessoryControlTapped+=OnCalloutAccessoryControlTapped;
}
}
}
//事件委托
CalloutAccessoryControltApped上的私有无效(对象发送方,mkmapViewAccessorTappedEventArgs e)
{
// ...
}

您可以在该
视图中添加自定义的
uitappesturerecognizer
,以实现此效果,以下是步骤:

首先,在
CustomMapRenderer
中定义一个
ges

public class CustomMapRenderer : MapRenderer
{
    UIView customPinView;
    List<CustomPin> customPins;

    UITapGestureRecognizer ges;

    ...
}
并在[code>OnDidDecleAnnotationView
中将其删除:

void OnDidSelectAnnotationView(object sender, MKAnnotationViewEventArgs e)
{
    var customView = e.View as CustomMKAnnotationView;
    customPinView = new UIView();


    Action action = () => {

        if (!string.IsNullOrWhiteSpace(((CustomMKAnnotationView)customView).Url))
        {
            UIApplication.SharedApplication.OpenUrl(new Foundation.NSUrl(((CustomMKAnnotationView)customView).Url));
        }
    };

    ges = new UITapGestureRecognizer(action);
    customView.AddGestureRecognizer(ges);

    if (customView.MarkerId == "Xamarin")
    {
        customPinView.Frame = new CGRect(0, 0, 200, 84);
        var image = new UIImageView(new CGRect(0, 0, 200, 84));
        image.Image = UIImage.FromFile("xamarin.png");
        customPinView.AddSubview(image);
        customPinView.Center = new CGPoint(0, -(e.View.Frame.Height + 75));
        e.View.AddSubview(customPinView);
    }
}
void OnDidDeselectAnnotationView(object sender, MKAnnotationViewEventArgs e)
{

    var customView = e.View as CustomMKAnnotationView;
    customView.RemoveGestureRecognizer(ges);

    if (!e.View.Selected)
    {
        customPinView.RemoveFromSuperview();
        customPinView.Dispose();
        customPinView = null;
    }
}

请参阅:

我的解决方案对您有效吗?我需要TapSirture为customPinView工作(我在该区域内有一个按钮)。TapSirture for customView仅在我单击两次Pin时调用。还有别的选择吗?