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; }
