UIRefreshControl not showing in landscape when in a navigation controller with large titles

我的未来我决定 提交于 2021-02-07 09:16:15

问题


I have a plain UITableViewController embedded in a UINavigationController which prefers large titles. I added a refresh control to my table view controller.

On iPhone in iOS 11, if I launch my app in portrait mode, switch to landscape and begin refreshing the table view, the refresh control does not show up. The refresh happens, but the control is just not present. It's not even in the view hierarchy:

Note that the same does work on iPhone if I'm in portrait mode, and also on iPad in every orientation. It also works on iOS 10 with every device and every orientation and also works on iOS 11 if I disable large titles, so it obviously has something to do with the large titles.

Here is a screenshot from the same thing on iOS 10:

I made a sample project for this. There is no code involved, here is the whole setup in Interface Builder:

The same thing happens when I try it with a simple UIViewController with an embedded UITableView or UIScrollView.

I'm pretty sure this is a bug. How can I make the refresh control visible on iPhone in landscape?


回答1:


We fixed this by recreating the refresh control on every rotation. It's called in viewDidLoad() too.

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
    super.traitCollectionDidChange(previousTraitCollection)

    if traitCollection.verticalSizeClass != previousTraitCollection?.verticalSizeClass {
        tableView.refreshControl = UIRefreshControl() // !!!
        tableView.refreshControl.addTarget(self, action: #selector(didPullToRefresh), for: .valueChanged)
    }
}

@objc func didPullToRefresh() {
    DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
        tableView.refreshControl.endRefreshing()
    }
    // ...
}



回答2:


This can clearly be characterized as a bug. It's readily reproduced. Your description seems quite correct; once you've exposed the refresh control in portrait and then rotated to landscape, the refresh control isn't even in the interface in landscape (that's easy to see if you give it a background color).

On the whole, however, this is not very surprising. There are many bugs connected with large titles; Apple clearly hasn't thought through this feature very carefully.



来源:https://stackoverflow.com/questions/48544268/uirefreshcontrol-not-showing-in-landscape-when-in-a-navigation-controller-with-l

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