AnnotationView在calloutVIew上重叠

问题描述 投票:1回答:1

我正在使用MapKit在地图上显示数据。为此,我使用Custom AnnotationView和Custom CalloutView。但问题是当我让AnnotationView在那时相互关闭时,AnnotationView在CalloutView上重叠。这是问题的屏幕截图。 overlapping annotationView

按钮也有问题,按钮的点击事件没有被调用。 calloutView下方的4个按钮不会被点击调用。但右上角的代表编辑事件的按钮在点击时会被触发。

这是我的CalloutView代码。

@implementation CustomCalloutView

- (id)init {

        return self;
}
- (IBAction)btnEditAction:(UIButton *)sender {

    [self.delegate btnEditClicked];
}

- (IBAction)btnMailAction:(UIButton *)sender {

    [self.delegate btnMailClicked];
}

- (IBAction)btnMessageAction:(UIButton *)sender {

    [self.delegate btnMessageClicked];
}

- (IBAction)btnCallAction:(UIButton *)sender {

    [self.delegate btnCallClicked];

}

- (IBAction)btnStreetAction:(UIButton *)sender {

    [self.delegate btnStreetClicked];
}
- (IBAction)CalloutTapGestureClicked:(UITapGestureRecognizer*)sender {
    [self.delegate CalloutTApGesture:sender];
}
@end

请帮我解决这个问题......

ios objective-c mapkit mkannotationview
1个回答
0
投票

这样做是为了防止重叠(在顶部插入callOut视图)

 func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView)
 {

   print("clickedddddddd")

    if view.annotation is MKUserLocation
    {
        return
    }

        let customView = (Bundle.main.loadNibNamed("customSou", owner: self, options: nil))?[0] as! customSouOut;

        var calloutViewFrame = customView.frame;
        calloutViewFrame.origin = CGPoint(x:-calloutViewFrame.size.width/2 + 15,y: -calloutViewFrame.size.height);
        customView.frame = calloutViewFrame;


        view.addSubview(customView)


         // here you can fill any label or button with data according to it's pin 

         //

        for v in view.subviews
        {
            if v is customSouOut
            {
                continue
            }
            else
            {
                view.insertSubview(customView, aboveSubview: v)
            }
        }

    }

}

func mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView)
{
     print("oppspspspsps")

    if view.annotation is MKUserLocation
    {
        return
    }

     for v in view.subviews
    {
        if v is customSouOut 
        {
            v.removeFromSuperview()

            break
        }
    }




}
© www.soinside.com 2019 - 2024. All rights reserved.