我可以消除MKMapView注释点击事件的延迟吗?

时间:2017-01-24 22:22:22

标签: macos mkmapview mapkit mkannotationview

我有一个MKMapView,里面有一些注释。

我有一个MKMapViewDelegate,实现了mapView(_:didSelect:)。它有效,但有明显的滞后。在点击注释和接收此消息之间,有大约半秒的延迟。

在其他类型的视图中,我捕获点击事件,它们是即时的。在地图上,只有几个注释,它们只有少量数据 - 而不是性能瓶颈。

有没有办法绕过延迟,马上获取MKMapView注释的点击事件?延迟不是世界末日,但它非常烦人。

1 个答案:

答案 0 :(得分:0)

您可以尝试声明注释的按钮:

let smallSquare = CGSize(width: 30, height: 30)  // The size of the button.
let button = UIButton(frame: CGRect(origin: CGPointZero, size: smallSquare))   // To initialize the button with the size.

button.addTarget(self, action: #selector(ViewController.a_function), forControlEvents: .TouchUpInside)
your_pinView.leftCalloutAccessoryView = button   
// I do not know how to use all the space of the view. 
// You can also do like this:
// your_pinView.rightCalloutAccessoryView = button 
// And add an image to bring out the button BEFORE SET THE BUTTON IN THE ANNOTATION like this:
// button.setBackgroundImage(UIImage(named: "car"), forState: .Normal)

如果选择该按钮,则会调用此函数,调用函数a_function()(在我的示例中)。

您的功能应如下所示:

func a_function () {

    print ("Annotation selected!"); 

}

我不知道这是不是你想要的,但是对于我来说,它很短暂的延迟。