Detect if app is running in Slide Over or Split View mode in iOS 9
Just another way to repackage all of this
extension UIApplication {
public var isSplitOrSlideOver: Bool {
guard let w = self.delegate?.window, let window = w else { return false }
return !window.frame.equalTo(window.screen.bounds)
}
}
then you can just
UIApplication.shared.isSplitOrSlideOver
in SwiftUIApplication.sharedApplication.isSplitOrSlideOver
in Objective-C
Note that, in Swift, the window
object is a double optional... WTF!
For iOS 13+ (note, I haven't tested the iOS 13 code myself yet)
extension UIApplication {
public var isSplitOrSlideOver: Bool {
guard let window = self.windows.filter({ $0.isKeyWindow }).first else { return false }
return !(window.frame.width == window.screen.bounds.width)
}
}
Just check if your window occupies the whole screen:
BOOL isRunningInFullScreen = CGRectEqualToRect([UIApplication sharedApplication].delegate.window.frame, [UIApplication sharedApplication].delegate.window.screen.bounds);
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
-(void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
{
// simply create a property of 'BOOL' type
isRunningInFullScreen = CGRectEqualToRect([UIApplication sharedApplication].delegate.window.frame, [UIApplication sharedApplication].delegate.window.screen.bounds);
}