Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjust a UIScrollView height based on a UITableView

I have a UIScrollView which contains a UIView and a UITableView. My goal is to adjust the height of the UIScrollView to allow me to scroll the contents of the UIScrollView to a specific point.

Here is my view: It has a UIView up top and a UITableView down below.

enter image description here

When I scroll, I want the UIView to stop at a specific point like so: enter image description here

The tableView would be able to continue scrolling, but the UIView would be locked in place until the user scrolled up and brought the UIView back to its original state.

A prime example of what I am trying to do is the AppStore.app on iOS 6. When you view the details of the app, the filter bar for Details, Reviews and Related moves to the top of the screen and stops. I hope this all made sense.

Thanks

like image 387
Anthony Castelli Avatar asked Oct 22 '22 13:10

Anthony Castelli


1 Answers

I ended up going with a simpler approach. can't believe I didn't see this before. I created two views, one for the UITableView's tableHeaderView and one for the viewForHeaderInSection. The view I wanted to remain visible at all times is placed in the viewForHeaderInSection method and the other view is placed in the tableHeaderView property. This is a much simpler approach, I think than using a scrollview. The only issue I have run into with this approach is all my UIView animations in these two views no longer animate. Here is my code.

[self.tableView setTableHeaderView:self.headerView];

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
     return self.tableViewHeader;
}
like image 133
Anthony Castelli Avatar answered Oct 29 '22 19:10

Anthony Castelli