Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView direction of scrolling

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?

like image 895
Alex Tau Avatar asked Jun 29 '12 13:06

Alex Tau


People also ask

How do I turn off horizontal scrolling in Swift?

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.

What is scroll view in Swift?

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.

How do I use horizontal ScrollView in react native?

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).

Which is a property of UIScrollView?

→ UIScrollView has 3 main properties, known as contentSize, contentOffset, and contentInset.


1 Answers

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");
    }
}
like image 169
Alex Tau Avatar answered Nov 15 '22 06:11

Alex Tau