我意识到当从父 UIViewcontroller 打开一个新的 UIVewcontroller 并触摸我的 ChildViewContorller 上的空白区域(没有 GUI 元素控件)时,它调用了 Parents touchesBegan:
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
我 parent 的观点(在屏幕上不可见)。
什么错误或如何防止这种情况?
最佳答案
我确实以这种方式在我的应用程序中解决了这个问题 1.首先定义一个代表当前 View Controller 的枚举
enum ViewControllerState {
case FirstViewController
case SecondViewController
// ....
}
2。然后定义一个协议(protocol),为那些需要这种行为的 View Controller 定义这个规则
protocol ViewControllerStatePresentation {
var viewControllerState: ViewControllerState
}
3。接下来,让所有 View Controller (那些需要此行为的 View Controller )确认此协议(protocol)。
class ViewController: ViewControllerStatePresentation {
var viewControllerState: ViewControllerState!
}
4.现在,当您呈现 subview Controller 时,然后更改 viewControllerState。当 viewControllerState 为 childViewController 时,将 childViewController 的父 View userInteractionEnabled
属性设置为 false,否则将其设置为 true。
关于ios - 打开 subview 后背景 uiview 仍然可触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32114053/