如何检查设备的方向?

ema*_*ine 3 iphone xcode objective-c ipad

我正在寻找一种快速的方法来判断设备是否通过主页按钮向右或向左按住.有这样的功能吗?

Eri*_*ric 8

看看UIDevice文档.有一个定向属性.就像是:

UIDeviceOrientation d = [[UIDevice currentDevice] orientation];
Run Code Online (Sandbox Code Playgroud)

d您正在寻找的价值是:

UIDeviceOrientationLandscapeLeft - 设备处于横向模式,设备直立,主页按钮位于右侧.

UIDeviceOrientationLandscapeRight - 设备处于横向模式,设备直立,主页按钮位于左侧.