首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >calloutVIew上的AnnotationView重叠

calloutVIew上的AnnotationView重叠
EN

Stack Overflow用户
提问于 2017-12-21 02:16:09
回答 1查看 161关注 0票数 2

我正在使用MapKit在地图上显示数据。为此,我使用了自定义AnnotationView和自定义CalloutView。但问题是,当我让AnnotationView彼此关闭时,AnnotationView在CalloutView上是重叠的。以下是该问题的屏幕截图。

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

以下是我的CalloutView代码。

代码语言:javascript
复制
@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

请帮我解决这个问题。

EN

回答 1

Stack Overflow用户

发布于 2017-12-21 02:30:06

这样做可以防止重叠(在顶部插入callOut视图)

代码语言:javascript
复制
 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
        }
    }




}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47912093

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档