如何通过刷新控制来限制拉距?

我正在尝试使用UIRefreshControlUITableView加载一些数据。 我做了,

 - (void)scrollViewDidScroll:(UIScrollView *)scrollView { // Get the current size of the refresh controller CGRect refreshBounds = refreshControl.bounds; // Distance the table has been pulled >= 0 CGFloat pullDistance = MAX(0.0, -self.newsTableView.contentOffset.y); // Half the width of the table CGFloat midX = self.newsTableView.frame.size.width / 2.0; CGFloat spinnerHeight = self.compass_spinner.bounds.size.height; CGFloat spinnerHeightHalf = spinnerHeight / 2.0; CGFloat spinnerWidth = self.compass_spinner.bounds.size.width; CGFloat spinnerWidthHalf = spinnerWidth / 2.0; // Set the Y coord of the graphics, based on pull distance CGFloat spinnerY = pullDistance / 2.0 - spinnerHeightHalf; // Calculate the X coord of the graphics, adjust based on pull ratio CGFloat spinnerX = (midX - spinnerWidthHalf); // When the compass and spinner overlap, keep them together self.isRefreshIconsOverlap = YES; // If the graphics have overlapped or we are refreshing, keep them together if (self.isRefreshIconsOverlap || refreshControl.isRefreshing) { spinnerX = midX - spinnerWidthHalf; } CGRect spinnerFrame = self.compass_spinner.frame; spinnerFrame.origin.x = spinnerX; spinnerFrame.origin.y = spinnerY; self.compass_spinner.frame = spinnerFrame; // Set the encompassing view's frames refreshBounds.size.height = pullDistance; self.refreshColorView.frame = refreshBounds; self.refreshLoadingView.frame = refreshBounds; // If we're refreshing and the animation is not playing, then play the animation if (refreshControl.isRefreshing && !self.isRefreshAnimating) { [self animateRefreshView]; } } 

使用这个代码,我可以将表视图拉下到屏幕的底部。 我的UIRefresControl像

  // Initialize Refresh Control refreshControl = [[UIRefreshControl alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)]; // Configure Refresh Control [refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged]; 

要使用此刷新,我需要拖动像屏幕的1/2。 我怎样才能在短暂的拖动(拉)刷新?

为了缩短UIRefreshControl的拉距,你可以试试这个:

 - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView.contentOffset.y < -110 && ![refreshControl isRefreshing]) { [refreshControl beginRefreshing]; //your code for refresh [refreshControl endRefreshing]; } } 

也许你遇到了这个问题,因为你错误地设置了刷新控制。 不要使用帧init刷新控制。 只要做[[alloc] init][new]并把它作为表视图的背景视图。 表视图知道如何处理它。

 self.myRefreshControl = [UIRefreshControl new]; [self.myRefreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged]; [self.myTableView setBackgroundView:self.myRefreshControl]; 

这是你通常如何设置一个拉来刷新控制。 但是,如果这仍然不能满足你,你可以UIRefreshControl ,这绝对不是一个最佳的解决scheme,或者你可以欺骗UIScrollView委托方法的东西作为tnyleebuild议。 但是在scrollViewDidScroll自定义默认行为并不是一个明智的决定。