我有一个看起来像这样的视图层次结构:UIView (A)UIView > UIImageViewUIView > UIView (B)UIView > UIView (B) > Rounded Rect ButtonUIView > UIView (B) > UIImageViewUIView > UIView (B) > UILabel我已将手势识别器附加到我的UIView(B)。我面临的问题是我没有对UIView(B)内的Rounded Rect Button采取任何操作。singleTap手势识别器捕获/覆盖按钮的“ Touch Up Inside”事件。我该如何运作?我认为响应者链层次结构将确保将优先考虑按钮触摸事件,并且它将被触发!我想念什么?以下是一些相关代码:#pragma mark -#pragma mark View lifecycle (Gesture recognizer setup)- (void)viewDidLoad { [super viewDidLoad]; // double tap gesture recognizer UITapGestureRecognizer *dtapGestureRecognize = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapGestureRecognizer:)]; dtapGestureRecognize.delegate = self; dtapGestureRecognize.numberOfTapsRequired = 2; [self.viewB addGestureRecognizer:dtapGestureRecognize]; // single tap gesture recognizer UITapGestureRecognizer *tapGestureRecognize = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureRecognizer:)]; tapGestureRecognize.delegate = self; tapGestureRecognize.numberOfTapsRequired = 1; [tapGestureRecognize requireGestureRecognizerToFail:dtapGestureRecognize]; [self.viewB addGestureRecognizer:tapGestureRecognize]; // add gesture recodgnizer to the grid view to start the edit mode UILongPressGestureRecognizer *pahGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureRecognizerStateChanged:)]; pahGestureRecognizer.delegate = self; pahGestureRecognizer.minimumPressDuration = 0.5; [self.viewB addGestureRecognizer:pahGestureRecognizer]; [dtapGestureRecognize release]; [tapGestureRecognize release]; [pahGestureRecognizer release];}#pragma mark -#pragma mark Button actions- (IBAction)buttonTouchUpInside:(id)sender { NSLog(@"%s, %@", __FUNCTION__, sender);}#pragma mark -#pragma mark Gesture recognizer actions- (void)singleTapGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer { NSLog(@"%s", __FUNCTION__);}
3 回答
开心每一天1111
TA贡献1836条经验 获得超13个赞
在“ shouldReceiveTouch”方法中,应添加一个条件,如果触摸按钮,则该条件将返回NO。
这来自苹果的SimpleGestureRecognizers示例。
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
// Disallow recognition of tap gestures in the segmented control.
if ((touch.view == yourButton)) {//change it to your condition
return NO;
}
return YES;
}
希望对你有帮助
正如丹尼尔(Daniel)指出的那样,您必须遵守UIGestureRecognizerDelegate它才能正常工作。
- 3 回答
- 0 关注
- 569 浏览
添加回答
举报
0/150
提交
取消