UITapGestureRecognizer不会启动UIView子类

Vin*_*tro 6 iphone objective-c uiview uigesturerecognizer ios5

我已经创建了UIView的自定义子类,因为我需要覆盖drawRect方法.我尝试添加一个UITapGestureRecognizer,但这对我不起作用.这里,我的ViewController的代码:

MyCustomView *customView = [[MyCustomView alloc] initWithFrame:CGRectFrame(0, 30, 30, 30)];
[customView setUserInteractionEnabled:YES];

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doSomething)];
[customView addGestureRecognizer:tapGestureRecognizer];
Run Code Online (Sandbox Code Playgroud)

我不明白为什么当我触摸我的UIView子类对象时,手势识别器不会启动.

非常感谢提前!

固定了!

我的观点是在UIImageView上,而UIImageView没有userInteractionEnabled设置为YES.

Vin*_*tro 13

固定了!

我的观点是在UIImageView上,而UIImageView没有userInteractionEnabled设置为YES.