简体   繁体   English

UIButton没有回应接触

[英]UIButton not responding to touches

I've the following view: 我有以下观点:

在此输入图像描述

The way it is build up 它的建立方式

UIViewController --> UIView (bottom square) --> UIViewController (is loaded in the bottom square) UIViewController - > UIView(底部方块) - > UIViewController(加载在底部方块中)

Button presses within in this UIViewController are not being triggered. 不会触发此UIViewController中的按钮按下。 However I do see the button animate when I press down in the simulator. 但是,当我在模拟器中按下时,我确实看到了按钮的动画效果。

Also when I add the following tap handler programmatically to the round UIImageView in this UIViewController it responds: 此外,当我以编程方式将以下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)

How can I catch actions upon these buttons? 如何捕捉这些按钮的动作? This isn't working: 这不起作用:

@IBAction func test(sender: AnyObject) {
        print("test")
    }

The line is connected to the UIButton in interface builder btw: 该行连接到界面构建器btw中的UIButton:

在此输入图像描述

I found the solution. 我找到了解决方案。 I just had this to add the ViewController to the View: 我只是将ViewController添加到View中:

self.popupView.addSubview(userPopupView.view)

When it should have been: 什么时候应该是:

self.addChildViewController(userPopupView)
self.popupView.addSubview(userPopupView.view)
userPopupView.didMoveToParentViewController(self)

Now it works! 现在它有效!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM