Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 373
Nikita Pestrov Avatar asked Mar 12 '13 11:03

Nikita Pestrov


1 Answers

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});

like image 158
Nikita Pestrov Avatar answered Nov 18 '22 10:11

Nikita Pestrov