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

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


        
7条回答
  •  梦谈多话
    2021-02-03 21:46

    Swift 3+

    switch UIDevice.current.orientation {
    case .faceUp:
      print("flat - up")
    case .faceDown:
      print("flat - down")
    case .landscapeLeft:
      print("landscape - left")
    case .landscapeRight:
      print("landscape - right")
    case .portrait:
      print("portrait - normal")
    case .portraitUpsideDown:
      print("portrait - upsideDown")
    case .unknown:
      print("unknown")
    }
    

提交回复
热议问题