2017-07-02 49 views

回答

1

是的,你可以確認到協議的UITableViewDelegate和實施-scrollViewDidScroll方法。每當用戶滾動tableView時調用此方法。

此外,您可以檢查scrollView的contentOffset並將其與最後一個進行比較。

@property (assign, nonatomic) CGFlaot lastContentOffset 

- (void)scrollViewDidScroll:(UIScrollView *)scrollView { 
    if (scrollView.contentOffset.y > self.lastContentOffset.y) { 
     // Scroll down direction 
    } else { 
     // Scroll to up 
    } 
    self.lastContentOffset = currentOffset; 
} 

而且不要忘記設置tableViewDelegate

self.tableView.delegate = self; 
1

如果你想知道的是滾動視圖中或上下移動,你可以使用這個

func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { 
    let translation = scrollView.panGestureRecognizer.translation(in: scrollView.superview!) 
    if translation.y > 0 { 
     print("scrolling down") 
    } else { 
     print("scrolling up") 
    } 
} 

記得設置您的視圖控制器中的scrollView.delegate = self

0

是的,這是可能的!由於tableViewscrollView繼承,因此您可以使用UIScrollViewDelegate

  • 添加UIScrollViewDelegate
  • 現在執行這些代理功能scrollViewShouldScrollToTop,scrollViewDidScroll。現在你可以跟蹤通過對比tableView的委託功能的X - Position

示例實現您的tableView的移動:

func scrollViewDidScroll(_ scrollView: UIScrollView) 
{ 
    if scrollView == tableView // incase you have multiple scrollViews 
    { 
     print(scrollView.contentOffset.x) 
    } 

} 
0

這麼簡單,如下。

-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView 
        withVelocity:(CGPoint)velocity 
      targetContentOffset:(inout CGPoint *)targetContentOffset{ 

    if (velocity.y > 0){ 
     NSLog(@"scrolling up"); 
    } 
    if (velocity.y < 0){ 
     NSLog(@"scrolling down"); 
    } 
} 
相關問題