相关疑难解决方法(0)

UICollectionViewController中的Pull-to-refresh

我想UICollectionViewController在iOS 6下实现pull-down-to-refresh .这很容易实现UITableViewController,如下所示:

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(startRefresh:)
    forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
Run Code Online (Sandbox Code Playgroud)

以上实现了一个漂亮的液滴动画作为本机小部件的一部分.

由于UICollectionViewController"更加进化",UITableViewController人们会期待某种功能的奇偶性,但我无法在任何地方找到参考来实现这一点的内置方式.

  1. 有一种简单的方法可以做到这一点,我忽略了吗?
  2. 可以UIRefreshControl用某种方式使用UICollectionViewController,尽管报头和文档都指出它的意思与表视图中使用?

uikit ios6 pull-to-refresh

73
推荐指数
3
解决办法
3万
查看次数

在iOS7中使用UICollectionView的UIRefreshControl

在我的应用程序中,我使用刷新控件和集合视图.

UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds];
collectionView.alwaysBounceVertical = YES;
...
[self.view addSubview:collectionView];

UIRefreshControl *refreshControl = [UIRefreshControl new];
[collectionView addSubview:refreshControl];
Run Code Online (Sandbox Code Playgroud)

iOS7有一些令人讨厌的错误,当你向下拉集合视图并且在刷新开始时不释放你的手指时,垂直contentOffset移动20-30点向下,这导致丑陋的滚动跳跃.

如果你在外面使用刷新控件,表也有这个问题UITableViewController.但是对于他们来说,可以通过将您的UIRefreshControl实例分配给UITableView名为的私有属性来轻松解决_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];
Run Code Online (Sandbox Code Playgroud)

但是UICollectionView没有这样的属性所以必须有一些方法来手动处理它.

objective-c uitableview ios uicollectionview uirefreshcontrol

31
推荐指数
1
解决办法
1万
查看次数

在ViewController中的UICollectionView中刷新以刷新

我在下面使用了以下代码 UICollectionViewController

override func viewDidLoad() {            

    self.collectionView!.alwaysBounceVertical = true
    let refresher = UIRefreshControl()
    refresher.addTarget(self, action: "refreshStream", forControlEvents: .ValueChanged)

    refreshControl = refresher
    collectionView!.addSubview(refreshControl!)
}

func refreshStream() {

    print("refresh")
    self.collectionView?.reloadData()

    refreshControl?.endRefreshing()

}
Run Code Online (Sandbox Code Playgroud)

现在我需要它与UICollectionView内部工作,UIViewController我用Google搜索了一个小时,但无法让它工作.我感谢任何帮助.

ios swift

31
推荐指数
4
解决办法
3万
查看次数