【发布时间】:2025-12-14 09:30:01
【问题描述】:
我正在努力从手势识别器中获得我想要的行为,特别是如果其他手势被触发则取消某些手势。
我有一个 scrollView 设置为分页和每个页面中的多个子视图。如果用户点击页面的右侧或左侧,我添加了一个触摸手势识别器以滚动到下一页或上一页。
// Add a gesture recogniser turn pages on a single tap at the edge of a page
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureHandler:)];
tapGesture.cancelsTouchesInView = NO;
[self addGestureRecognizer:tapGesture];
[tapGesture release];
还有我的手势处理程序:
- (void) tapGestureHandler:(UIGestureRecognizer *) gestureRecognizer {
const CGFloat kTapMargin = 180;
// Get the position of the point tapped in the window co-ordinate system
CGPoint tapPoint = [gestureRecognizer locationInView:nil];
// If the tap point is to the left of the page then go back a page
if (tapPoint.x > (self.frame.size.width - kTapMargin)) [self scrollRectToVisible:pageViewRightFrame animated:YES];
// If the tap point is to the right of the page then go forward a page
else if (tapPoint.x < kTapMargin) [self scrollRectToVisible:pageViewLeftFrame animated:YES];
}
一切正常,除了我在页面上有一个带有按钮的子视图。如果用户触摸 subView 上的按钮,我希望能够忽略点击翻页,但我不知道该怎么做。
干杯
戴夫
【问题讨论】:
标签: iphone cocoa-touch uibutton uigesturerecognizer