我正在使用 MapKit 在 map 上显示数据。为此,我使用自定义 AnnotationView 和自定义 CalloutView。但问题是,当我让 AnnotationView 相互关闭时,AnnotationView 在 CalloutView 上重叠。这是问题的截图。
按钮也有问题,按钮的点击事件没有被调用。 calloutView 下方的 4 个按钮不会在点击时被调用。但是右上角代表编辑事件的按钮在点击时会被触发。
这是我的 CalloutView 代码。
@implementation CustomCalloutView
- (id)init {
return self;
}
- (IBAction)btnEditActionUIButton *)sender {
[self.delegate btnEditClicked];
}
- (IBAction)btnMailActionUIButton *)sender {
[self.delegate btnMailClicked];
}
- (IBAction)btnMessageActionUIButton *)sender {
[self.delegate btnMessageClicked];
}
- (IBAction)btnCallActionUIButton *)sender {
[self.delegate btnCallClicked];
}
- (IBAction)btnStreetActionUIButton *)sender {
[self.delegate btnStreetClicked];
}
- (IBAction)CalloutTapGestureClickedUITapGestureRecognizer*)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/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |