在主视图控制器中添加子视图无法执行按钮单击事件

时间:2016-10-06 10:11:22

标签: swift

let secondVC = SecondViewController(nibName: "SecondViewController", bundle: nil)        
        var cgRectFrame = secondVC.view.frame
        cgRectFrame.origin = CGPoint(x: self.view.frame.origin.x, y:self.view.frame.origin.y+64)
        cgRectFrame.size = CGSize(width: self.view.frame.size.width, height: self.view.frame.size.height)
        secondVC.view.frame = cgRectFrame
        IBMainView.addSubview(secondVC.view)

2 个答案:

答案 0 :(得分:0)

尝试secondVC.view.isUserInteractionEnabled = true

答案 1 :(得分:0)

在代码中添加“self.addChildViewController(viewController_object)”

    let secondVC = SecondViewController(nibName: "SecondViewController", bundle: nil)

    self.addChildViewController(secondVC)
    var cgRectFrame = secondVC.view.frame
    cgRectFrame.origin = CGPoint(x: self.view.frame.origin.x, y:self.view.frame.origin.y+64)
    cgRectFrame.size = CGSize(width: self.view.frame.size.width, height: self.view.frame.size.height)
    secondVC.view.frame = cgRectFrame
    IBMainView.addSubview(secondVC.view)