在我的应用程序中,我使用带有 Collection View 的刷新控件。
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds];
collectionView.alwaysBounceVertical = YES;
...
[self.view addSubview:collectionView];
UIRefreshControl *refreshControl = [UIRefreshControl new];
[collectionView addSubview:refreshControl];
iOS7 有一些讨厌的错误,当您下拉 Collection View 并且在刷新开始时不松开手指时,垂直 contentOffset
会向下移动 20-30 点,从而导致难看的滚动跳转。
如果您在 UITableViewController
之外使用带有刷新控制的表,它们也会有这个问题。但是对于他们来说,可以通过将您的 UIRefreshControl
实例分配给 UITableView
的名为 _refreshControl
的私有(private)属性来轻松解决:
@interface UITableView ()
- (void)_setRefreshControl:(UIRefreshControl *)refreshControl;
@end
...
UITableView *tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.view addSubview:tableView];
UIRefreshControl *refreshControl = [UIRefreshControl new];
[tableView addSubview:refreshControl];
[tableView _setRefreshControl:refreshControl];
但是 UICollectionView
没有这样的属性,所以必须有一些方法来手动处理它。
最佳答案
遇到同样的问题并找到了似乎可以解决的解决方法。
这似乎是因为当您拉过 ScrollView 的边缘时 UIScrollView
正在减慢对平移手势的跟踪。但是,UIScrollView
不考虑跟踪期间对 contentInset 的更改。 UIRefreshControl
在激活时更改 contentInset,此更改导致跳转。
覆盖 UICollectionView
上的 setContentInset
并解决这种情况似乎有帮助:
- (void)setContentInset:(UIEdgeInsets)contentInset {
if (self.tracking) {
CGFloat diff = contentInset.top - self.contentInset.top;
CGPoint translation = [self.panGestureRecognizer translationInView:self];
translation.y -= diff * 3.0 / 2.0;
[self.panGestureRecognizer setTranslation:translation inView:self];
}
[super setContentInset:contentInset];
}
有趣的是,UITableView
通过在您拉 PAST 刷新控件之前不减慢跟踪来解决这个问题。但是,我看不到这种行为的暴露方式。
关于ios - 在 iOS7 中使用 UICollectionView 的 UIRefreshControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19483511/