阐述
梳理现公司代码时发现 isExclusiveTouch 出现很多次,但是对其不是很熟悉,学习并记录一下。
记录
1 官方介绍
A Boolean value that indicates whether the receiver handles touch events exclusively.
Setting this property to true causes the receiver to block the delivery of touch events
to other views in the same window. The default value of this property is false.
简单的解释就是这个属性决定当前事件处理者(控件)在它处理事件的时候是否允许其它控件进行事件处理工作。
通俗讲:
当设置了 isExclusiveTouch = true 的控件(View)是事件的第一响应者,那么到你的所有手指离开屏幕前,其他的控件(View)是不会响应任何触摸事件的。
2 拓展
isExclusive 可以对单个控件实例设置,这样确保此控件实例对应的业务不会被其它事情所影响。
var button1 = UIButton()
button1.isExclusiveTouch = true
isExclusive 也可以统一设置控件,这样确保这个类型的控件对应的业务不会产生交错。(预防猴子测试) 如:
UIButton.appearance().isExclusiveTouch = true
当然,如果要设置类别的东西比较多,直接设置全局父类也是可行的。
UIView.appearance().isExclusiveTouch = true
3 注意
isExclusiveTouch 仅支持 iOS 8.0+
引用
1 https://www.jianshu.com/p/14ad9c94557c
2 https://www.jianshu.com/p/8c505df3b16d