2016-06-25 2 views
2

同様の質問Stop UITableView over scroll at top & bottom?がありますが、私は若干異なる機能が必要です。私は自分のテーブルが底部でオーバースケールできるようにしたいが、トップでオーバースケールすることはできない。 私は理解されるように、UITableViewの上端を止めるのを止めますか?

tableView.bounces = false 

は、上部と下部の両方にoverscrolling無効にすることができ、しかし、私は上部でこれを無効にする必要があります。同様

tableView.bouncesAtTheTop = false 
tableView.bouncesAtTheBottom = true 

答えて

3

あなたは(あなたがのtableViewのデリゲートする必要があります)のtableViewのscrollViewDidScrollbounceプロパティを変更することにより、それを達成することができます

はlastYのプロパティを持っている:

var lastY: CGFloat = 0.0 

viewDidLoadに初期バウンスを設定します。

tableView.bounces = false 

と:スイフト2.2

2
func scrollViewDidScroll(scrollView: UIScrollView) { 
    let currentY = scrollView.contentOffset.y 
    let currentBottomY = scrollView.frame.size.height + currentY 
    if currentY > lastY { 
     //"scrolling down" 
     tableView.bounces = true 
    } else { 
     //"scrolling up" 
     // Check that we are not in bottom bounce 
     if currentBottomY < scrollView.contentSize.height + scrollView.contentInset.bottom { 
      tableView.bounces = false 
     } 
    } 
    lastY = scrollView.contentOffset.y 
} 

、オブジェクティブC

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{ 
if (scrollView.contentOffset.y<=0) { 
    scrollView.contentOffset = CGPointZero; 
} 

}の

func scrollViewDidScroll(scrollView: UIScrollView) { 
    if scrollView == self.bootcampStartedTableView { 
     if scrollView.contentOffset.y <= 0 { 
      scrollView.contentOffset = CGPoint.zero 
     } 
    } 
} 

を使用

関連する問題