[英]UIButton not responding to touches
我有以下观点:
它的建立方式
UIViewController - > UIView(底部方块) - > UIViewController(加载在底部方块中)
不会触发此UIViewController中的按钮按下。 但是,当我在模拟器中按下时,我确实看到了按钮的动画效果。
此外,当我以编程方式将以下tap处理程序添加到此UIViewController中的圆形UIImageView时,它会响应:
func handleTap(sender: UITapGestureRecognizer? = nil) {
print("tappable")
}
let tap = UITapGestureRecognizer(target: self, action: #selector(NeighbourhoodViewController.handleTap(_:)))
userPopupView.userImageView.userInteractionEnabled = true
userPopupView.userImageView.addGestureRecognizer(tap)
如何捕捉这些按钮的动作? 这不起作用:
@IBAction func test(sender: AnyObject) {
print("test")
}
该行连接到界面构建器btw中的UIButton:
我找到了解决方案。 我只是将ViewController添加到View中:
self.popupView.addSubview(userPopupView.view)
什么时候应该是:
self.addChildViewController(userPopupView)
self.popupView.addSubview(userPopupView.view)
userPopupView.didMoveToParentViewController(self)
现在它有效!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.