Michal Gumny Michal Gumny - 1 year ago 88
iOS Question

Hiding a toolbar element when UITableView scrolls (similar to Facebook's app?)

How I can achieve this effect?

full top view half top view
top view almost hidden

Answer Source

This isn't immediately noticeable from your screenshots, but I believe you want the that header toolbar to slide up as the user scrolls, right? (I'd suggest clarifying on that part)

You can do this a few ways, and in all of them you will have to implement your own scrolling logic, meaning how much the header toolbar slides up depending on where you have scrolled. That said, here's how to do it:

1. If you're using UITableView, I assume you've got your view controller set as its delegate. Since UITableView is a subclass of UIScrollView already, just add the UIScrollViewDelegate to your view controller. That will give us scroll events as they happen. You'll want to do your logic in scrollViewDidScroll:.

2.. If you're simply using UIScrollView, just set your view controller as its delegate, implement UIScrollViewDelegate, and do your logic in scrollViewDidScroll:.

That said, your code might look something like this:

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

    if(scrollPos.y >= 40 /* or CGRectGetHeight(yourToolbar.frame) */){
        // Fully hide your toolbar
    } else {
        // Slide it up incrementally, etc.

Anyway, hope I helped.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download