在scrollView上增加滑動手勢(Pan)


 

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM