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()
}
//数据源 代理相关方法省略....
}
网友评论