在iOS7中使用UICollectionView的UIRefreshControl [英] UIRefreshControl with UICollectionView in iOS7

查看:150
本文介绍了在iOS7中使用UICollectionView的UIRefreshControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用带有集合视图的刷新控件。

In my application I use refresh control with 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有一些令人讨厌的错误,当你向下拉集合视图时,刷新时不要松开手指开始,垂直 contentOffset 向下移动20-30点,这会导致丑陋的滚动跳转。

iOS7 has some nasty bug that when you pull collection view down and don't release your finger when refreshing begins, vertical contentOffset shifts for 20-30 points down which results in ugly scroll jump.

表有这个问题如果你在 UITableViewController 之外的刷新控制中使用它们也是如此。但对于他们来说,可以通过将 UIRefreshControl 实例分配给 UITableView 的私有属性<$ c $来轻松解决c> _refreshControl :

Tables have this problem too if you use them with refresh control outside of UITableViewController. But for them it could be easily solved by assigning your UIRefreshControl instance to UITableView's private property called _refreshControl:

@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 没有这样的属性所以必须有一些方法来手动处理它。

But UICollectionView does not have such property so there must be some way to deal with it manually.

推荐答案

遇到同样的问题,找到一个似乎可以修复它的解决方法。

Having the same problem and found a workaround that seems to fix it.

这似乎正在发生,因为 UIScrollView 当你拉过时,会减慢对平移手势的追踪速度scrollview的边缘。但是, UIScrollView 未考虑跟踪期间对contentInset的更改。 UIRefreshControl 在激活时更改contentInset,此更改导致跳转。

This seems to be happening because the UIScrollView is slowing down the tracking of the pan gesture when you pull past the edge of the scrollview. However, UIScrollView is not accounting for changes to contentInset during tracking. UIRefreshControl changes contentInset when it activates, and this change is causing the jump.

覆盖你的 UICollectionView 上的setContentInset 并且这个案例的会计似乎有帮助:

Overriding setContentInset on your UICollectionView and accounting for this case seems to help:

- (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刷新控件来解决此问题。但是,我没有看到这种行为暴露的方式。

Interestingly, UITableView accounts for this by NOT slowing down tracking until you pull PAST the refresh control. However, I don't see a way that this behavior is exposed.

这篇关于在iOS7中使用UICollectionView的UIRefreshControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆