接口:
@interface MyViewController : UIViewController <UIGestureRecognizerDelegate>
实现:
- (void)dismissPopup {
NSLog(@"popup view dismissed");
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldReceiveTouch:(UITouch *)touch {
return touch.view == self.view;
}
-(void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(dismissPopup)];
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.delegate = self;
[self.view addGestureRecognizer:tapRecognizer];
//...
}
从未触发解雇方法,为什么?我在iOS7上,使用故事板。
touch.view
的日志MYAPP[5779:60b] <UIView: 0x17ecd8b0; frame = (0 0; 320 418);
autoresize = RM+BM; layer = <CALayer: 0x17ecd910>>
self.view:
MYAPP[5779:60b] <UIView: 0x17ecd590; frame = (0 64; 320 504);
autoresize = RM+BM; gestureRecognizers = <NSArray: 0x17eb2c70>; layer
= <CALayer: 0x17ecd5f0>>
从调试器记录:http://dpaste.com/1768718/
答案 0 :(得分:1)
我的工作正常。
如果你在断点
gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
你可以确保touch.view在你的实现中实际上是self.view吗?