userInteractionEnabled与enabled的区别

首先.userInteractionEnabled是UIView类中的一个属性.
enabled是UIControl类中的一个属性.
UIControl继承与UIView.
在响应者链中有这么一段描述

UIKit uses view-based hit-testing to determine where touch events occur. Specifically, UIKit compares the touch location to the bounds of view objects in the view hierarchy. The hitTest:withEvent: method of UIView traverses the view hierarchy, looking for the deepest subview that contains the specified touch, which becomes the first responder for the touch event.

就是说通过hitTest:withEvent:这个方法来寻找响应的视图.hitTest:withEvent:方法中有这么一段记载

This method ignores view objects that are hidden, that have disabled user interactions, or have an alpha level less than 0.01. This method does not take the view’s content into account when determining a hit. Thus, a view can still be returned even if the specified point is in a transparent portion of that view’s content.

意思是,如果视图隐藏或者userinteractions(用户交互,也就是userInteractionEnabled属性).或者alpha < 0.01.hitTest会自动忽略(往下继续传递).

所以说.如果设置userInteractionEnabled为NO.点击方法或者是触摸事件之类的会穿透视图.
而设置enabled为NO的话会禁止该控件的交互,并且.事件不会穿透.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值