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

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


        
7条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-03 21:48

    you can do something like,

    if UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeLeft{
    
    }
    else if UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeRight{
    
    }
    else if UIDevice.currentDevice().orientation == UIDeviceOrientation.UIDeviceOrientationPortraitUpsideDown{
    
    }
    else if UIDevice.currentDevice().orientation == UIDeviceOrientation.UIDeviceOrientationPortrait{
    
    }
    

    SWIFT 5

        if UIDevice.current.orientation.isLandscape {
    
        } else if UIDevice.current.orientation.isFlat {
    
        } else if UIDevice.current.orientation.isPortrait {
    
        } else if UIDevice.current.orientation.isValidInterfaceOrientation {
    
        }
    

    SWIFT 3

    if UIDevice.current.orientation == UIDeviceOrientation.landscapeLeft {
    
    } else if UIDevice.current.orientation == UIDeviceOrientation.landscapeRight {
    
    } else if UIDevice.current.orientation == UIDeviceOrientation.portrait {
    
    } else if UIDevice.current.orientation == UIDeviceOrientation.portraitUpsideDown {
    
            } 
    

提交回复
热议问题