如何在swift中检查设备方向是左侧还是右侧? [英] How to check if device orientation is landscape left or right in swift?

查看:202
本文介绍了如何在swift中检查设备方向是左侧还是右侧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    if UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation) {
        print("landscape")
    }
    if UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation){
        print("portrait")
    }

如何我可以检查它的横向是左还是右?

How can I check if it's landscape left or right?

推荐答案

你可以做类似的事情,

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 3

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 {

        } 

这篇关于如何在swift中检查设备方向是左侧还是右侧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆