gpt4 book ai didi

ios - UIRefreshControl 需要下拉太多

转载 作者:IT王子 更新时间:2023-10-29 08:06:11 33 4
gpt4 key购买 nike

我正在尝试在我的项目中的 UICollectionView 上实现 UIRefreshControl。它按预期工作,但我需要在旋转时将 UICollectionView 拉到 refreshControl 高度的大约 3 倍(一旦用户松开)。我见过其他应用程序,您只需要在旋转时下拉到 refreshControl 的高度。如何更改我需要下拉的数量?

代码:

(void)viewDidLoad {
[super viewDidLoad];

[self.collectionView setBackgroundColor:[UIColor clearColor]];
self.refreshControl = [UIRefreshControl new];
[self.refreshControl addTarget:self action:@selector(refreshFavorites) forControlEvents:UIControlEventValueChanged];
[self.collectionView addSubview:self.refreshControl];
self.collectionView.alwaysBounceVertical = YES;
}

附件是帮助形象化我的意思的图片。我的 collectionView 有一行(纯红色)。红色和 refreshControl 之间的空间就是我拉下以尝试激活 refreshControl 的空间。

在这张图片中,我几乎激活了控件,并且已经在屏幕上下拉了相当多的内容。

enter image description here

在这张图片中,我激活了控件并开始加载(在它跳转 ~20-30 像素后,但它仍然突出显示这是多么重要)

enter image description here

此图像显示控件在被激活并正在执行动画后处于“静止”状态。

enter image description here

我试过设置 UIRefreshControl 的框架来控制高度,但这不起作用。我还更改了 collectionView:layout:sizeForItemAtIndexPath 中的大小,但这没有帮助。

最佳答案

如果需要将 UIRefreshControl 拉得太远而无法触发,则可能是 iOS SDK 的错误。

我建议在 View Controller 的帮助下解决这个问题:

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// Force update the snapping height of refresh control.
[self.refreshControl didMoveToSuperview];
}

另外如果不介意使用私有(private)API,需要更精准的控制,可以这样写:

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
@try {
[self.refreshControl setValue:@(60) forKey:@"_snappingHeight"];
}
@catch (NSException *exception) {
}
}

这适用于 iOS 7-10。没有 App Store 审核问题。


往里看

UIRefreshControl 有一个名为 snappingHeight 的属性。此属性控制用户需要下拉的距离。但不幸的是,这个值并不总是正确设置,尤其是你有一个自定义 View 层次结构。

UIRefreshControl有一个私有(private)方法调用_updateSnappingHeight,这个方法也在didMoveToSuperview中调用。因此,手动 didMoveToSuperview 调用可能会更新错误的捕捉值。

关于ios - UIRefreshControl 需要下拉太多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28886365/

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