ios - AnnotationView 在 calloutVIew 上重叠

标签 ios objective-c mapkit mkannotationview

我正在使用 MapKit 在 map 上显示数据。为此,我使用了 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

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

最佳答案

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

 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
        }
    }




}

关于ios - AnnotationView 在 calloutVIew 上重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47912093/

相关文章:

ios - Facebook iOS SDK发布帖子-感到兴奋等

objective-c - 如何获取给定路径的文件大小?

swift - 折线未显示在 MapKit [Xcode 9.0 - Swift 4.0]

ios - Swift 3 中的 Firebase 多级数据库处理

ios - 自定义 UIButton 不显示

objective-c - Flac 转换器 Objective-C?

iphone - 通过 Storyboard的选项卡栏项目

ios - 如何注册应用程序来开设地点

ios - 无法在 MKMapView 中显示多个注释图钉

ios - Web 应用程序 iOS、黑莓