Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Growing header in UITableView as user pulls

I'm trying to add a UIView above a UITableView. The intention is that as the user pulls the content down (as one normally would for a pull-to-refresh), instead of the UITableView's background showing, the UIView above the table should grow to stay stuck to the top UITableViewCell that is sliding down. As the user scrolls the other way (content going up), the UIView would disappear as if it was just the top UITableViewCell.

You can see this implementation in Path (pull down timeline and top profile picture expands, example at 0:15) and the new Facebook app's checkin (with the map growing above the list of nearby places).

Not sure the best way to go about this. I think to achieve a similar effect you'd have to have the UIView as the first cell. But this question has me a bit worried about trying to resize the height of the cell as they scroll. In theory the resize only need to happen as they pull down, not push up, if it's just the top UITableViewCell.

Edit: Current code - using suggestion from rummad I'm adding a keypath observer on the tableview for contentOffset and resizing the cell's height based on that, but it's jumping all over the place.

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
    if (self.tableView == (UITableView*)object) {
        if ([keyPath isEqualToString:@"contentOffset"]) {
            CGPoint scrollLoc = self.tableView.contentOffset;
            if (scrollLoc.y < 0) {
                NSLog(@"offset:%@", NSStringFromCGPoint(scrollLoc));
                headerSize = 100 - scrollLoc.y;
                [self.tableView beginUpdates];
                [self.tableView endUpdates];
            }
        }
    }
}
like image 230
Parrots Avatar asked Sep 25 '12 14:09

Parrots


2 Answers

Actually looks like there are a few libraries out there, and using the first table cell is not the way to go. "Parallax" seemed to be the magic google term.

http://rowboatrevolution.com/2012/02/uitableview-parallax-background-a-la-path/ https://github.com/Rheeseyb/RBParallaxTableViewController

like image 63
Parrots Avatar answered Nov 16 '22 19:11

Parrots


In your viewDidScroll: delegate method track the contentOffset for your UITableView. You can then set the UIView's frame accordingly.

like image 4
runmad Avatar answered Nov 16 '22 20:11

runmad