我有几个IBActions附加到UIButtons。 IBActions工作正常,直到我添加以下代码:
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"View Did Load");
[self addGestureRecognizersToView:drawImage];
}
在我添加那段代码之后,IBActions不会触发。当我触摸它们时,UIButtons突出显示,但没有任何IBAction代码被击中。
这是我的addGestureRecognizers代码:
- (void)addGestureRecognizersToView:(UIImageView *)theView {
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[panGesture setMaximumNumberOfTouches:2];
[panGesture setMinimumNumberOfTouches:1];
//panGesture.delegate = drawImage;
[theView addGestureRecognizer:panGesture];
[panGesture release];
UITapGestureRecognizer *doubleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
[doubleFingerTap setNumberOfTapsRequired:2];
[self.view addGestureRecognizer:doubleFingerTap];
[doubleFingerTap release];
UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[singleFingerTap setNumberOfTapsRequired:1];
[self.view addGestureRecognizer:singleFingerTap];
[singleFingerTap release];
}
如果我注释掉singleFingerTap代码,它就可以了。我猜我不应该使用alloc,因为我之前已经在doubleFingerTap中分配了一次?
关于我在这里可能缺少什么的想法?
答案 0 :(得分:1)
您的单指敲击会妨碍按钮的正常行为。你必须确保触摸得不受阻碍。
[singleFingerTap setCancelsTouchesInView:NO];
答案 1 :(得分:0)
听起来UITapGestureRecognizer是intercepting the taps否则将由UIButtons处理。
您可以使用gestureRecognizer:shouldReceiveTouch:
:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
return (touch.view != self.button1 &&
touch.view != self.button2);
}
或者,你可以hack the responder chain。