How to add refresh control to collection view large titles navigation bar in iOS 11?

耗尽温柔 提交于 2019-12-04 10:23:21

问题


According to Apple the refresh control should be part of the large title navigation bar in iOS 11.

The refresh control is part of the navigation bar (on pull to refresh) when I enabled the refresh control in my storyboard for a UITableViewController.

I can not do this in storyboard for all other views like UICollectionViewController. When I add a refresh control in code as a subview it is not part of the navigation bar:

refreshControl = UIRefreshControl()
collectionView?.addSubview(refreshControl)

It looks like this though:

How can I add a refresh control to my custom scroll view like UICollectionViewController in such a way that the refresh control is displayed in the navigation bar when large titles is used?


回答1:


As of iOS 10, UITableView and UICollectionView has refreshControl property.

So, instead of:

tableView.addSubview(refreshControl)

you do:

tableView.refreshControl = refreshControl

and this should work for new big headers in iOS 11.




回答2:


EDIT: The documentation has been updated at some point, and below information is not longer true.

As specified by Apple in UIRefreshControl documentation.

Note Because the refresh control is specifically designed for use in a table view that's managed by a table view controller, using it in a different context can result in undefined behavior.

If your VC is a UITableViewController it will work exactly like in system apps.



来源:https://stackoverflow.com/questions/44942330/how-to-add-refresh-control-to-collection-view-large-titles-navigation-bar-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!