我想当一个 View 被触摸或点击时,它的处理程序首先被调用,然后它的父 View 的处理程序被调用(向上传播)。
但是如果superview的userInteractionEnabled
设置为NO,那么所有的subviews和offspring也不能进行用户交互是真的吗?如果我们只想禁用主视图但不想禁用 subview 怎么办?
最佳答案
您可以覆盖 hitTest(_:withEvent:)
以忽略 View 本身,但仍会向其 subview 传递触摸。
class ContainerStackView : UIStackView {
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
let result = super.hitTest(point, with: event)
if result == self { return nil }
return result
}
}
关于iphone - 在 iOS 上,如果一个 super View 的 userInteractionEnabled 是 NO,那么所有的 subview 也会被禁用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10880868/