简体   繁体   English

UISplitViewController 始终在 iPad 纵向模式 iOS 9 中显示主视图

[英]UISplitViewController always show master view in iPad portrait mode iOS 9

I'm building a universal app using UISplitViewController and targeting iOS 9 and above.我正在使用 UISplitViewController 构建一个通用应用程序,并针对 iOS 9 及更高版本。 The app language is Objective-C.应用程序语言是Objective-C。

Having started with the Xcode Master/Detail template and set up my views in the standard way, I'm realising that the app will be better if I keep the master view on screen at all times (on iPad), including when the device is in portrait mode.开始使用 Xcode Master/Detail 模板并以标准方式设置我的视图后,我意识到如果我始终将主视图保持在屏幕上(在 iPad 上),包括当设备处于运行状态时,应用程序会更好在纵向模式。 However, no matter how hard I search, I can't find anything to help me learn how this is achieved.但是,无论我多么努力地搜索,我都找不到任何东西可以帮助我了解这是如何实现的。 I know this was previously achieved using splitViewController:shouldHideViewController:inOrientation:我知道这是以前使用 splitViewController:shouldHideViewController:inOrientation 实现的:

However, this method is deprecated in iOS 9 and I can't figure out what replaces it and why.但是,此方法在 iOS 9 中已弃用,我无法弄清楚替换它的内容以及原因。 I've looked at the new delegate methods for UISplitViewController and find them completely lacking in any level of intuitiveness.我查看了 UISplitViewController 的新委托方法,发现它们完全缺乏任何级别的直观性。

I'd really appreciate some pointers in regard to what replaces splitViewController:shouldHideViewController:inOrientation: and how it can be used to keep the master view displayed at all times on the iPad.我真的很感激关于什么取代 splitViewController:shouldHideViewController:inOrientation: 以及如何使用它来保持主视图始终显示在 iPad 上的一些指示。

Subclass UISplitViewController子类 UISplitViewController

There is no need to specifically track orientation changes: Master and Detail will still be displayed in sequence on iPhone in portrait mode, and most iPhone in landscape mode.无需专门跟踪方向变化:iPhone 纵向模式下仍会按顺序显示 Master 和 Detail,而大多数 iPhone 横向模式下仍会显示 Master 和 Detail。
preferredDisplayMode:.allVisible only affects the modes where both views can be simultaneously visible. preferredDisplayMode:.allVisible仅影响两个视图可以同时可见的模式。

Swift迅速

class SplitViewController: UISplitViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        preferredDisplayMode = .allVisible
    }
}

Obj-C对象-C

- (void)viewDidLoad {
    [super viewDidLoad];
    self.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;

}

iPad Portrait & iPhone 8 Plus Landscape iPad 纵向iPhone 8 Plus 横向

在此处输入图片说明

如果有人最近检查了这个话题,IOS 14 中不推荐使用 .allVisible,请使用:splitVC.preferredDisplayMode = .oneBesideSecondary

aSplitViewController.preferredDisplayMode = .oneBesideSecondary

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

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