Detect if app is running in Slide Over or Split View mode in iOS 9

后端 未结 15 2476
死守一世寂寞
死守一世寂寞 2020-12-04 15:31

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 mult

15条回答
  •  忘掉有多难
    2020-12-04 16:22

    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 Swift
    • UIApplication.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)
        }
    }
    

提交回复
热议问题