Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS7 UIRefreshControl changes contentInset

I have a UINavigationController in my app. The UINavigationBar is set to opaque and all the scroll views do not overlap underneath the bar.

In one view I have a UITableView. The frame of the UITableView is (0 0; 320 504) on my iPhone 5. i.e. the height is 568 - 64 (the height of the nav bar and status bar).

The contentInset of the UITableView is (0, 0, 0, 0). When the table view first loads the contentOffset is (0, 0).

This is fine. Works brilliantly.

I added a UIRefreshControl to the table view. This works a couple of times but then after a few times of doing pull to refresh then the content at the top gets "stuck" under the nav bar.

When this happens I inspect the contentInset and it is now (-60, 0, 0, 0).

Is there any way to stop the UIRefreshControl from changing the contentInset?

like image 476
Fogmeister Avatar asked Nov 20 '13 16:11

Fogmeister


2 Answers

You need override setContentInset: in you UICollectionView

- (void)setContentInset:(UIEdgeInsets)contentInset {
  if (self.tracking) {
    CGFloat difference = contentInset.top - self.contentInset.top;
    CGPoint translation = [self.panGestureRecognizer translationInView:self];
    translation.y -= difference * 3.0 / 2.0;
    [self.panGestureRecognizer setTranslation:translation inView:self];
  }
  [super setContentInset:contentInset];
}
like image 129
Sergey Petruk Avatar answered Nov 13 '22 21:11

Sergey Petruk


Reset your table view contentInset.

-(void)pullToRefresh
{
    [self.tableView reloadData];
    [self.refreshControl endRefreshing];
    [self.tableView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
}
like image 33
situee Avatar answered Nov 13 '22 22:11

situee