CodexBloom - Programming Q&A Platform

How to implement guide with uisplitviewcontroller not resizing correctly on iphone in landscape mode

๐Ÿ‘€ Views: 316 ๐Ÿ’ฌ Answers: 1 ๐Ÿ“… Created: 2025-06-13
iOS Swift UISplitViewController

I'm deploying to production and I'm deploying to production and I've been working on this all day and I am currently developing an iPhone app using Swift (Xcode 14.1) that utilizes `UISplitViewController` for a split view layout... The question arises when I rotate the device to landscape mode; the detail view does not resize correctly and often overlaps with the master view, causing a poor user experience. I have set the preferred display mode to `.allVisible`, but it seems like it defaults back to `.automatic` upon rotation. Hereโ€™s the relevant code snippet that I have implemented in my `UISplitViewController` setup: ```swift let splitViewController = UISplitViewController() splitViewController.preferredDisplayMode = .allVisible splitViewController.viewControllers = [masterViewController, detailViewController] self.window?.rootViewController = splitViewController self.window?.makeKeyAndVisible() ``` In addition, I have overridden the `viewWillTransition(to:with:)` method to handle the rotation, but even after adjusting constraints in this method, the layout does not respond as expected: ```swift override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { super.viewWillTransition(to: size, with: coordinator) coordinator.animate(alongsideTransition: { _ in // Adjust constraints or perform layout updates here }, completion: nil) } ``` I also noticed the following warning in the console when I rotate to landscape: `Warning: Attempt to present <UIViewController: 0x...> on <UISplitViewController: 0x...> while a presentation is in progress!` which seems to indicate that there might be an scenario with view controller transitions during rotation. Iโ€™ve tried manually invalidating the layout within the transition block, but that didnโ€™t help either. Has anyone else faced this scenario? Any suggestions on how to ensure the detail view resizes correctly in landscape mode on iPhone? I'm working on a API that needs to handle this. I'd really appreciate any guidance on this. I recently upgraded to Swift stable. Thanks for taking the time to read this! I recently upgraded to Swift 3.10. I'd really appreciate any guidance on this. This is happening in both development and production on Linux. Could this be a known issue? I'm open to any suggestions.