【发布时间】:2017-05-02 15:12:06
【问题描述】:
我正在使用 MKMapView 构建地图应用程序,但我似乎无法在 MKAnnotationView 的子视图中进行交互。
我有一个 UIView 类作为 MKAnnotationView 的主要子视图,在那里我有另一个子视图 UIButton,如下所示:
let button = UIButton(type: .infoLight)
button.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
button.addTarget(self, action: #selector(self.buttonTapped(sender:)), for: UIControlEvents.touchUpInside)
//self.bringSubview(toFront: button)
//button.isUserInteractionEnabled = true
self.addSubview(button)
(注释行似乎没有帮助)
那么类中的 tapped 函数是这样的:
func buttonTapped(sender: UIButton!) {
print("button tapped:", sender)
}
知道为什么 buttonTapped() 方法不会触发吗?
【问题讨论】:
标签: swift mkmapview mkannotationview