什么是UIDevice.currentDevice()。orientation.isLandscape的目标c等价物?

时间:2017-09-03 05:28:16

标签: ios objective-c

以下swift声明的objc代码是什么?

if (UIDevice.currentDevice().orientation.isLandscape)

我到目前为止所知道的是

  if  ([[UIDevice currentDevice] orientation])

2 个答案:

答案 0 :(得分:1)

来自apple Docs: -

BOOL UIDeviceOrientationIsLandscape(UIDeviceOrientation orientation);
  

返回一个布尔值,指示设备是否在   景观定位。

所以试试这个: -

  if(UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)){
    //True if landscape is on
}

答案 1 :(得分:1)

UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
BOOL isLandscape = UIDeviceOrientationIsLandscape(orientation);
if (isLandscape) {
    NSLog(@"Landscape orientation")
    //Do the work
}