Reputation: 8661
I am trying to hide an element synced to the scroll. But the scroll bounce effect mess up my animation.
override func scrollViewDidScroll(scrollView: UIScrollView) {
if (self.lastContentOffset > scrollView.contentOffset.y) {
"Animate UIView up"
}
else if (self.lastContentOffset < scrollView.contentOffset.y){
"Animate UIView down"
}
Is there any other way I can get the direction I am scorlling without the bounce messing it up. I dont want to disable the bounce either.
Also since I am animating my uiview synced to the scroll, eg I scroll 10px up then the uiview height should be minimized by 10px do I then need layoutifneeded() or any other function?
Upvotes: 2
Views: 442
Reputation: 19892
When it's bouncing you can assume that it's scrolling "out of bounds", you can check for that like this and only animate the view when it's not out of bounds.
//Bouncing at the bottom
scrollView.contentOffset.y + scrollView.bounds.size.height > scrollView.contentSize.height;
// Bouncing at the top
scrollView.contentOffset.y < 0
You might need to tweak this code if you the contentInset
property is different from UIEdgeInsetZero
Upvotes: 3