I'm doing that pull-down-to-refresh thing. In scrollViewDidEndDecelerating I check if the offset is past a certain point and in scrollViewDidEndDragging I set the contentInset so as to keep the pulled-down section visible.
However, this results in flickering, probably due to the contentInset being reset during scrolling animation. I thought I might be able to prevent this by setting the targetContentOffset in scrollViewWillEndDragging, but it doesn't seem to do the trick.
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (scrollView.contentOffset.y < -kRefreshViewDelta)
{
self.tableView.contentInset = UIEdgeInsetsMake(kRefreshViewHeight, 0.0f, 0.0f, 0.0f);
}
}
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
if (scrollView.contentOffset.y < -kRefreshViewDelta)
{
targetContentOffset->y = kRefreshViewHeight ;
}
}
If you change the frame assigned to the UITableView at all (during the scrolling or otherwise), it will cause the contentInset to be reset to the default (0,0,0,0). There is some state checking for mine, but essentially this is what I've done for mine...
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView
willDecelerate:(BOOL)decelerate {
if (scrollView.contentOffset.y < -kRefreshDeltaY) {
animation = ^{
[self setContentInset:UIEdgeInsetsMake(kRefreshDeltaY,
0, 0, 0)];
};
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionAllowUserInteraction
animations:animation
completion:completion];
} // if
}
As long as I didn't lay out subviews or change the frame of the UITableView, it behaved fine for me.