// 1.
图像视图默认不支持用户交互
self
.
imageView
.
userInteractionEnabled
=
NO
;
// 2.
透明度
<= 0.01
的时候,不能接受交互
// self.imageView.alpha = 0.02;
// 3.
隐藏
不能接受交互
// self.imageView.hidden = YES;
//
用代码向图像视图添加按钮
//
如果父视图不接收用户交互,那么其中的所有子视图,同样不支持用户交互!
UIButton
*btn = [
UIButton
buttonWithType
:
UIButtonTypeContactAdd
];
[
self
.
imageView
addSubview
:btn];
[btn
addTarget
:
self
action
:
@selector
(click)
forControlEvents
:
UIControlEventTouchUpInside
];
//
第
4
种情况,如果子视图所在位置,超出了父视图的有效范围,是不能交互的
//
即便没有设置
clipsToBounds
,也只能显示,但是不能交互!
//
裁剪红色视图,不显示超出范围
self
.
redView
.
clipsToBounds
=
YES
;
UIButton
*btn = [
UIButton
buttonWithType
:
UIButtonTypeContactAdd
];
[btn
addTarget
:
self
action
:
@selector
(click)
forControlEvents
:
UIControlEventTouchUpInside
];
[
self
.
redView
addSubview
:btn];