I would like to copy the effect seen in Pinterest app, where they hide top and bottom bars depending on the direction of scrolling. My question is: what is the correct way to determine which way the UIScrollView is scrolling?
All your imageview textview etc must be in content view. Normally the scrollview won't scroll if the contentsize. width <= width of the scrollview, so if you don't want to do any calculation, safely set the contentsize. width = 0; that will eliminate the scroll for sure.
The scroll view displays its content within the scrollable content region. As the user performs platform-appropriate scroll gestures, the scroll view adjusts what portion of the underlying content is visible. ScrollView can scroll horizontally, vertically, or both, but does not provide zooming functionality.
In the ScrollView, we can scroll the components in both direction vertically and horizontally. By default, the ScrollView container scrolls its components and views in vertical. To scroll its components in horizontal, it uses the props horizontal: true (default, horizontal: false).
→ UIScrollView has 3 main properties, known as contentSize, contentOffset, and contentInset.
This is the solution:
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
pointNow = scrollView.contentOffset;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y<pointNow.y) {
DLog(@"down");
} else if (scrollView.contentOffset.y>pointNow.y) {
DLog(@"up");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With