简体   繁体   English

UIRefreshControl在具有大标题的导航控制器中不显示横向

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

I have a plain UITableViewController embedded in a UINavigationController which prefers large titles . 我有一个简单的UITableViewController嵌入在UINavigationController ,它更喜欢大型游戏 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 . 在iOS 11的iPhone上,如果我以纵向模式启动我的应用程序,切换到横向并开始刷新表格视图, 刷新控件不会显示 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. 需要注意的是同样的情形在iPhone上在每个方向的工作,如果我在纵向模式是,也iPad上。 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. 它也适用于iOS 10适用于所有设备和每个方向,如果我禁用大型游戏,它也适用于iOS 11 ,因此它显然与大型游戏有关。

Here is a screenshot from the same thing on iOS 10: 以下是iOS 10上同一内容的截图:

iOS 10上刷新控件的屏幕截图

I made a sample project for this. 我为此做了一个示例项目。 There is no code involved, here is the whole setup in Interface Builder: 没有涉及代码,这是Interface Builder中的整个设置:

设置截图

The same thing happens when I try it with a simple UIViewController with an embedded UITableView or UIScrollView . 当我尝试使用带有嵌入式UITableViewUIScrollView的简单UIViewController ,会发生同样的事情。

I'm pretty sure this is a bug. 我很确定这是一个错误。 How can I make the refresh control visible on iPhone in landscape? 如何在横向上显示iPhone上的刷新控件?

We fixed this by recreating the refresh control on every rotation. 我们通过在每次旋转时重新创建刷新控件来修复此问题。 It's called in viewDidLoad() too. 它也在viewDidLoad()中调用。

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()
    }
    // ...
}

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. Apple显然没有仔细考虑过这个功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM