iOS开发 在scrollView上增加滑动手势(Pan)

司宏伯
2023-12-01

view上有一个scrollView,现在想在view上加一个Pan手势,需求是:当向下划的时候,整个view动,但是scrollView不动;其它情况下scrollView动而view不动。

 

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}

// 给加的手势设置代理, 并实现此协议方法
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {

UIPanGestureRecognizer *pan = (UIPanGestureRecognizer *)gestureRecognizer;
CGPoint pos = [pan velocityInView:pan.view];
if (pos.y > 0) {
self.contentScrollView.scrollEnabled = NO;
return YES;
}
}

return NO;
}

转载于:https://www.cnblogs.com/diweinan/p/6213856.html

 类似资料: