在具有大标题的导航控制器中时,UIRefreshControl不以横向显示 [英] UIRefreshControl not showing in landscape when in a navigation controller with large titles

查看:76
本文介绍了在具有大标题的导航控制器中时,UIRefreshControl不以横向显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UINavigationController 中嵌入了一个普通的 UITableViewController ,其中首选大标题.我在表视图控制器中添加了刷新控件.

在iOS 11的iPhone上,如果我以纵向模式启动我的应用程序,切换到横向并开始刷新表格视图,刷新控件将不会显示.刷新发生,但控件不存在.它甚至不在视图层次结构中:

请注意,如果我处于纵向模式,那么在iPhone上也可以使用 ,而且在各个方向上的iPad上也都可以使用.它还可以在iOS 10上使用每种设备和每个方向,并且如果我禁用大标题,也可以在iOS 11上使用,因此显然与大标题有关.

以下是iOS 10上相同内容的屏幕截图:

当我使用带有嵌入式 UITableView UIScrollView 的简单 UIViewController 进行尝试时,也会发生相同的事情.

我很确定这是一个错误.如何使刷新控件在横向iPhone上可见?

解决方案

我们通过在每次旋转时重新创建刷新控件来解决此问题.它也在viewDidLoad()中调用.

 重写功能traitCollectionDidChange(__ previousTraitCollection:UITraitCollection?){super.traitCollectionDidChange(previousTraitCollection)如果traitCollection.verticalSizeClass!= previousTraitCollection?.verticalSizeClass {tableView.refreshControl = UIRefreshControl()//!!!tableView.refreshControl.addTarget(self,action:#selector(didPullToRefresh),for:.valueChanged)}}@objc func didPullToRefresh(){DispatchQueue.main.asyncAfter(最后期限:.now()+ 1){tableView.refreshControl.endRefreshing()}//...} 

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?

解决方案

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

这篇关于在具有大标题的导航控制器中时,UIRefreshControl不以横向显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆