Hiding the master view controller with UISplitViewController in iOS8

后端 未结 10 971
囚心锁ツ
囚心锁ツ 2020-12-12 19:06

I have an iOS7 application, which was based on the Xcode master-detail template, that I am porting to iOS8. One area that has changed a lot is the UISplitViewControlle

10条回答
  •  一向
    一向 (楼主)
    2020-12-12 19:30

    Very similar to the method by phatmann, but a bit simpler in Swift 5. And it's not technically a 'hack', as it is what the iOS doc suggested.

    In your prepareForSegue or other methods that handle touches, in

    let barButton = self.splitViewController?.displayModeButtonItem
    _ = barButton?.target?.perform(barButton?.action)
    

    According to Apple, the splitViewController's displayModeButtonItem is set up for you to display the master view controller in a way that suits your device orientation. That is, .preferHidden in portrait mode.

    All there's to do is to press the button, programatically. Or you can put it in an extension to UISplitViewController, like phatmann did.

提交回复
热议问题