In iOS 9, is it possible to detect when an app is running in iOS 9's Slide Over or Split View mode?
I've tried reading through Apple's documentation on iOS 9 multitasking, but haven't had any luck with this…
I ask because I might have a feature in my app that I'd like to disable when the app is opened in a Slide Over.
Like the solution by Dan Rosenstark, but changed to work on the new iPad Pro's that seem to report a different frame and screen.bounds height based on if it's ran directly on the device through Xcode, or if it is compiled and released through TestFlight or App Store. The height would return 980 when through AS or TF, rather than 1024 as it was supposed to like through Xcode causing it to be impossible to return true.
You can watch both -willTransitionToTraitCollection:withTransitionCoordinator: for the size class and viewWillTransitionToSize:withTransitionCoordinator: for the CGSize of your view. Hardcoding in size values isn't recommended though.
Just another way to repackage all of this
then you can just
UIApplication.shared.isSplitOrSlideOver
in SwiftUIApplication.sharedApplication.isSplitOrSlideOver
in Objective-CNote that, in Swift, the
window
object is a double optional... WTF!Just check if your window occupies the whole screen:
If this is false, then you're running in a split view or a slide over.
Here is the code snipped which will automatically maintain this flag irrespective of rotation
I wrote a
SizeClasser
library based on @Michael Voccola's library.You can initialize it with the
traitCollection
of your view controller and detect split views as well as device specific orientation.So you could write your code specifically 1/3 horizontal split view or 1/3 portrait split view which
UITraitCollection
does not give you a way to detect them.https://github.com/cemolcay/SizeClasser
I recently had to determine display style of an application based including, not only if it changed to split view or slide-over, but also what portion of the screen was being utilized for the application (full, 1/3, 1/2, 2/3). Adding this to a ViewController subclass was able to solve the issue.