gpt4 book ai didi

ios - 如何使用刷新控件限制拉动距离?

转载 作者:行者123 更新时间:2023-12-01 18:10:03 24 4
gpt4 key购买 nike

我正在尝试在 UITableView 中加载一些数据使用 UIRefreshControl .我做到了,

- (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];
}
}

使用此代码,我可以将表格 View 下拉到屏幕底部。我的 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];
}
}

关于ios - 如何使用刷新控件限制拉动距离?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33266018/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com