我只将横向模式应用于一个视图控制器。在那个视图控制器中,我使用的是集合视图。在纵向模式下一切正常。在横向模式下,除了导航栏标题和后退按钮外,模式数据显示完美。 我附上图片
人像模式
横向模式
我在横向模式下使用以下代码
extension UIApplication {
class func getTopViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
if let nav = base as? UINavigationController {
return getTopViewController(base: nav.visibleViewController)
}
if let tab = base as? UITabBarController {
if let selected = tab.selectedViewController {
return getTopViewController(base: selected)
}
}
if let presented = base?.presentedViewController {
return getTopViewController(base: presented)
}
return base
}
}
创建协议
protocol Rotatable {}
和打电话
class ComparePlans: UIViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate, UICollectionViewDataSource, Rotatable {
我不知道到底是什么问题。我尝试了不同的方法。任何帮助将不胜感激。