关于iOS10SDK中的refreshControl

作者: b9bd2a64f47e | 来源:发表于2016-11-30 16:37 被阅读95次
  • 前言

在iOS6中Apple首次加入了下拉刷新这种风格的控件,但是只能在UITableViewController中使用,不能在UIscrollView中使用,不能在collectionView中使用,当在UIViewControler创建UITableview时也不能使用。所以有很多人为UIScrollView做了扩展,来弥补上述的不足之处。比较优秀是MJRefresh,大家平时用的也几乎是这些第三方扩展。

在漫长的等待之后,在iOS10中Apple终于为UIScrollView加入了refreshControl。因为UITabelView和UICollectionView都继承自UIScrollView,所以在iOS10中你可苹果原生的refreshControl,不必再使用第三方扩展


  • refreshControl的使用方法

   UIRefreshControl*refreshControl = [UIRefreshControl new];
    refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"下拉刷新"];
 [refreshControl addTarget:self action:@selector(mRefresh) forControlEvents:UIControlEventValueChanged];
    _mTableView.refreshControl= refreshControl;

然后当用户下拉时就会调用方法

 - (void)mRefresh{
    NSLog(@"刷新");
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.mTableView.refreshControl endRefreshing];
    });
}
  • 注意

1、UIScrollView的refreshControl属性只在iOS10中才有。
2、不用设置refreshControl的frame,当你为UIScrollView添加refreshControl的时候,UIKit会自动的管理它。
3、refreshControl只响应UIControlEventValueChanged事件;

相关文章

网友评论

    本文标题:关于iOS10SDK中的refreshControl

    本文链接:https://www.haomeiwen.com/subject/wwxtmttx.html