6

Shouldn't it be always true for iPhone portrait mode? The answers here: UISplitViewController in portrait on iPhone shows detail VC instead of master don't really solve my problem.

yvetterowe
  • 1,239
  • 7
  • 20
  • 34
  • 1
    From apple's documentation: "The value of this property is false when the split view controller is capable of displaying both of its child view controllers at the same time, even if it is not showing them both at the moment." – Ramy Al Zuhouri Jun 02 '17 at 21:32
  • 1
    Yeah but on iPhone portrait mode, which is compact, it's not capable to display both master & detail screens right? – yvetterowe Jun 05 '17 at 17:14
  • 2
    In my case the value was false until viewDidLayoutSubviews() was called for the first time. – Klaas Apr 04 '19 at 19:07

3 Answers3

0

@Klaas comment is right on. I could only observe the value of isCollapsed be meaningful after the view is properly laid out and added to the view hierarchy with a proper trait collection. In my case moving logic that depended on isCollapsed from viewWillAppear to viewDidAppear did the trick.

Rafael Nobre
  • 5,062
  • 40
  • 40
0

For me, isCollapsed was false even after viewDidLayoutSubviews().

I ended up checking if the view controller's traitCollection.horizontalSizeClass was equal to .unspecified, then I know that isCollapsed is not ready to use yet.

You can then watch for changes on the traitCollection. In my case, I needed to know when horizontalSizeClass is .regular, so the following code did it:

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
    if traitCollection.horizontalSizeClass == .regular {
        ...
    }
}
Cody
  • 650
  • 9
  • 16
0

On iOS 14, I've found it's required to check if the view has been added to a window (self.view.window != nil) before trusting isCollapsed.

Dharman
  • 30,962
  • 25
  • 85
  • 135
adamup
  • 1,508
  • 19
  • 29