filou
filou

Reputation: 1619

Navigation- & Toolbar not hidden when UIScrollView scrolls

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

Upvotes: 0

Views: 910

Answers (2)

pawelropa
pawelropa

Reputation: 1439

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.

Upvotes: 1

Martin R
Martin R

Reputation: 539815

You should move

lastOffset = scrollView.contentOffset;

to the end of the method, otherwise

scrollView.contentOffset.y < lastOffset.y

will never be true.

Upvotes: 4

Related Questions