我在达到特定偏移时禁用UIScrollView,并希望在手势识别器中重新启用它。我唯一的问题是滚动视图在用户触摸从屏幕上移开之前不会触摸。
如何在不抬起手指的情况下重新启用滚动视图?
UIScrollViews类别:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
UIPanGestureRecognizer *gestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
gestureRecognizer.delegate = self;
gestureRecognizer.cancelsTouchesInView = NO;
gestureRecognizer.delaysTouchesBegan = NO;
gestureRecognizer.delaysTouchesEnded = NO;
[self.bodyScrollView addGestureRecognizer:gestureRecognizer];
- (void)handlePanGesture:(UIPanGestureRecognizer *)gesture
{
if (gesture.state == UIGestureRecognizerStateChanged) {
if (self.previousAssetsScrollViewOffset.y == -44
&& !self.bodyScrollView.scrollEnabled && !self.composeScrollView.scrollEnabled) {
self.bodyScrollView.scrollEnabled = YES;
self.composeScrollView.scrollEnabled = YES;
}
}
}
答案 0 :(得分:0)
一个问题是您没有区分手势的不同阶段(阶段)。因此,在整个手势中反复调用handlePanGesture:
,并且永远不会放弃对手势的控制,以便滚动视图可以检测到某些事情正在发生。基本上,你已经“吃掉”了整个手势,因此滚动视图永远不会听到它。
但是,即使你修复了这个问题,你仍然可能会遇到问题,因为一旦你的手势识别器识别出来,就不会有任何触摸传递到其他手势识别器,包括滚动视图。