Question

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    lastOffset = scrollView.contentOffset;

    if (scrollView.contentOffset.y < lastOffset.y) {
        [self.navigationController setNavigationBarHidden:YES animated:YES];
        [self.navigationController setToolbarHidden:YES animated:YES];
    }
    else {
        [self.navigationController setNavigationBarHidden:NO animated:YES];
        [self.navigationController setToolbarHidden:NO animated:YES];
    }
}

What am I doing wrong? The UIScrollViewDelegate is already set in my header file.

Was it helpful?

Solution

You should move

lastOffset = scrollView.contentOffset;

to the end of the method, otherwise

scrollView.contentOffset.y < lastOffset.y

will never be true.

OTHER TIPS

It's not hidden because every time code in else part is invoked. Suppose contentOffset = (100, 100) then you set last offset to equal contentOffset so if (scrollView.contentOffset.y < lastOffset.y) it will never be true. Put lastOffset = scrollView.contentOffset; on the end of scrollViewDidScroll method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top