ios UICollectionViewController 下拉刷新

class ViewController: UICollectionViewController {

    let refreshControl = UIRefreshControl()

    override func viewDidLoad() {
        super.viewDidLoad()
  
        //注意这里,collectionView 的 alwaysBounceVertical 必须打开
        //高度没有超过屏幕时不会开启滑动,当然也就无法触发下拉刷新
        self.collectionView?.alwaysBounceVertical = true
       
        refreshControl.tintColor = UIColor.grayColor()

        //下拉刷新
        //Selector 语法为 Swift 2.2
        refreshControl.addTarget(self, action: #selector(FlickrPhotosViewController.refresh), forControlEvents: UIControlEvents.ValueChanged)

        self.collectionView?.addSubview(refreshControl)
    }

    func refresh() {

        print("下拉刷新")
        refreshControl.endRefreshing()
    }

  //数据源 代理相关方法省略....
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容