UIImageView之userInteractionEnabled 属性

       我们往往喜欢用UIImageView最为我们程序的背景,然后再在其上面添加其他的控件。如果直接拖到控件到UImageView上面,可以发现控件并不是属于UIImageView,而是与其并列属于UIView的。但是用代码加的话发现可以用addSubView:方法给它上面加控件,但是程序运行起来就会发现UIImageView上面的控件(比如UIButton、UITextField)根本无法响应事件。这就要用到它的 userInteractionEnabled 属性。
     苹果帮助文档是这样解释的:

New image view objects are configured to disregard user events by default.

If you want to handle events in a custom subclass of UIImageView, you must explicitly change the value of the userInteractionEnabled property to YES after initializing the object.


userInteractionEnabled

A Boolean value that determines whether user events are ignored and removed from the event queue.

@property(nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled

Discussion

This property is inherited from the UIView parent class. This class changes the default value of this property to NO.

Availability

  • Available in iOS 2.0 and later.

Declared In

UIImageView.h


这就说明UIImageView默认是忽略事件的,不会响应事件的(用代码添加,会发现这个效果)。只有修改它的这个属性为YES它上面的控件才可以响应事件。也可以将其他控件直接加到VIew上面与UIImageView并列。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值