How Do I detect the orientation of the device on iOS?

后端 未结 12 919
小鲜肉
小鲜肉 2020-11-30 01:56

I have a question on how to detect the device orientation on iOS. I don\'t need to receive change notifications, just the current orientation itself. This seems to be a rath

12条回答
  •  情深已故
    2020-11-30 02:55

    Here is some Swift variables to make detection easier:

    let LANDSCAPE_RIGHT: Bool = UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeRight
    let LANDSCAPE_LEFT: Bool = UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeLeft
    let LANDSCAPE: Bool = LANDSCAPE_LEFT || LANDSCAPE_RIGHT
    let PORTRAIT_NORMAL: Bool = UIDevice.currentDevice().orientation == UIDeviceOrientation.Portrait
    let PORTRAIT_REVERSE: Bool = UIDevice.currentDevice().orientation == UIDeviceOrientation.PortraitUpsideDown
    let PORTRAIT: Bool = PORTRAIT_REVERSE || PORTRAIT_NORMAL
    

提交回复
热议问题