Nikita Pestrov
Nikita Pestrov

Reputation: 5966

Change the path needed for UIRefreshControl to go to UIControlEventValueChanged

I'm trying to add the UIRefreshControl to my UIScrollView, but the problem is that it's area is too small, so it's almost impossible for user to pull to the required level.

So is there a way to trigger the state of this control or change the length of the required pull gesture?

I know, that this control is new and there may be no straight way of achieving this, but maybe someone has found a hack?

Upvotes: 7

Views: 1398

Answers (1)

Nikita Pestrov
Nikita Pestrov

Reputation: 5966

Found a solution: make a delegate of your scrollView and in - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate refresh the control at some offset

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
  if (scrollView.contentOffset.y < -70) {
    [refreshControl beginRefreshing];
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
       [self handleRefresh:refreshControl];
     });
  }
}

Dispatch is made for not lagging the interface while getting info from server. If you then update something in your UI, use dispatch_async(dispatch_get_main_queue(), ^{//update UI code});

Upvotes: 7

Related Questions