I created a simple table view header in my UITableViewController:
UIView *tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, [[UIScreen mainScreen] bounds].size.height * 5 / 8)];
[tableHeaderView setBackgroundColor:[UIColor flatNavyBlueColorDark]];
[self.tableView setTableHeaderView:tableHeaderView];
Now I want to creating a snapping/elastic behaviour so that when the user scrolls the table header to the point that when 50% of it is out of the main screen's frame, the rest of it automatically snaps so that the whole header scrolls out. As described by these images:
user scrolls to this point(halfway) and lets go
At this point, the header automatically snaps close.
Help?
There's a method in UIScrollViewDelegate called scrollViewWillEndDragging:withVelocity:targetContentOffset:
, it gets called when the user stops scrolling, and lets you know where it's going to stop.
There you can check if targetContentOffset.y
is in the range you want, and modify it, which will cause the scroll view to stop in a different location.