How to check if device orientation is landscape left or right in swift?

前端 未结 7 1105
伪装坚强ぢ
伪装坚强ぢ 2021-02-03 21:22
    if UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation) {
        print(\"landscape\")
    }
    if UIDeviceOrientationIsPortrait(UIDevice.currentDev         


        
7条回答
  •  囚心锁ツ
    2021-02-03 21:52

    This works on Swift 3 & 4

    switch UIApplication.shared.statusBarOrientation {
        case .portrait:
            //do something
            break
        case .portraitUpsideDown:
            //do something
            break
        case .landscapeLeft:
        //do something
            break
        case .landscapeRight:
            //do something
            break
        case .unknown:
            //default
            break
     }
    

提交回复
热议问题