我意识到当从父UIViewcontroller打开一个新的UIVewcontroller并触摸childviewcontroller(没有GUI元素控件)上的空白时,它调用父触摸开始:

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {

我父母的观点(在屏幕上看不到)。
有什么问题或者如何预防?

最佳答案

我确实在我的应用程序中用这种方式解决了这个问题
一。首先定义表示当前视图控制器的枚举

enum ViewControllerState {
    case FirstViewController
    case SecondViewController
    // ....
}

2。然后为需要此行为的视图控制器定义此规则的协议
protocol ViewControllerStatePresentation {
    var viewControllerState: ViewControllerState
}

三。接下来,使所有视图控制器(需要此行为的视图控制器)确认此协议。
class ViewController: ViewControllerStatePresentation {
    var viewControllerState: ViewControllerState!
}

四。现在,当您呈现子视图控制器时,然后更改viewControllerState。当viewControllerState为childViewController时,将childViewController的父视图userInteractionEnabled属性设置为false,否则将其设置为true。

关于ios - 打开 subview 后,背景uiview仍可触摸,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32114053/

10-14 20:46