【问题标题】:AnnotationView overlapping on calloutVIewAnnotationView 在 calloutVIew 上重叠
【发布时间】:2017-12-20 18:16:08
【问题描述】:

我正在使用 MapKit 在地图上显示数据。为此,我使用自定义 AnnotationView 和自定义 CalloutView。但问题是,当我让 AnnotationView 相互关闭时,AnnotationView 与 CalloutView 重叠。这是问题的截图。

按钮也有问题,按钮的点击事件没有被调用。 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】:

    这样做是为了防止重叠(在顶部插入 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
            }
        }
    
    
    
    
    }
    

    【讨论】:

    • 什么是customSouOut?
    • 这是您想要作为标注视图的自定义视图,在您的示例中是包含无法使用的按钮的视图
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-31
    • 1970-01-01
    • 2023-03-03
    • 2021-01-22
    • 1970-01-01
    相关资源
    最近更新 更多