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

后端 未结 15 2462
死守一世寂寞
死守一世寂寞 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:17

    Here is a simpler and less fragile way with no constants, that I use in an iPhone/iPad iOS app.

    This code also distinguishes between slide over and split view.

    I'm returning String values here for clarity, feel free to use enum values and to merge the two cases of fullscreen as suits your app.

    func windowMode() -> String {
      let screenRect = UIScreen.main.bounds
      let appRect = UIApplication.shared.windows[0].bounds
    
      if (UIDevice.current.userInterfaceIdiom == .phone) {
        return "iPhone fullscreen"
      } else if (screenRect == appRect) {
        return "iPad fullscreen"
      } else if (appRect.size.height < screenRect.size.height) {
        return "iPad slide over"
      } else {
        return "iPad split view"
      }
    }
    

提交回复
热议问题