MKMapViewを使用してマップアプリケーションを構築していますが、MKAnnotationViewのサブビューで相互作用ができないようです。MKAnnotationViewのサブビューとしてのUIButtonが機能しない
私はMKAnnotationViewの主なサブビューとしてUIViewクラスを持って、そこに私はこのように、別のサブビュー、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)
(コメント行を助けていないようだ)
は、次にクラスのタップ機能は、次のようになります。buttonTapped()メソッドが起動しませんなぜ
func buttonTapped(sender: UIButton!) {
print("button tapped:", sender)
}
任意のアイデア?
ありがとう、私はそれを試してみよう! – Hexagons