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.
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.
@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.
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 {
...
}
}
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.