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

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


        
7条回答
  •  南方客
    南方客 (楼主)
    2021-02-03 21:47

    SWIFT 4.2

    if UIDevice.current.orientation == UIDeviceOrientation.landscapeLeft {
                    print("Landscape Left")
                } 
        else if UIDevice.current.orientation == UIDeviceOrientation.landscapeRight{
                    print("Landscape Right")
                } 
        else if UIDevice.current.orientation == UIDeviceOrientation.portraitUpsideDown{
                   print("Portrait Upside Down")
                } 
        else if UIDevice.current.orientation == UIDeviceOrientation.portrait {
                    print("Portrait")
        }
    

提交回复
热议问题