当iphone设备方向朝上/朝下时,我可以判断它是风景还是肖像? [英] when iphone Device orientation is face up/down, can I tell if it´s landscape or portrait?

查看:110
本文介绍了当iphone设备方向朝上/朝下时,我可以判断它是风景还是肖像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了这段代码,如果设备处于横向左/右或倒置,它会旋转并显示另一个视图控制器。但如果它朝上或面朝下,那么如何判断它是横向模式还是纵向?因为我只想面朝上或朝下并且在横向模式下旋转

I got this code that if the device is in landscape left/right or upside down it rotates and shows another view controller. but if it´s in the orientation face up or face down, then how can I tell if it´s in landscape mode or portrait? cause I only want to rotate if it´s face up or down and in landscape mode

    - (void)viewDidAppear:(BOOL)animated
    {
        UIDeviceOrientation orientation = [[UIDevice currentDevice]orientation];
        NSLog(@"orientation %d", orientation);
        if ((orientation == 2) || (orientation == 3) || (orientation == 4))
        {

            [self performSegueWithIdentifier:@"DisplayLandscapeView" sender:self];
            isShowingLandscapeView = YES;
    }
}


推荐答案

In UI代码通常不应取决于设备方向,而是用户界面方向。它们之间通常有区别,例如当视图控制器仅支持纵向时。

In UI code you usually should not depend on the device orientation but the user interface orientation. There's often a difference between them, for example when a view controller only supports portrait.

对于您的情况,最重要的区别是界面方向永远不会面朝上/朝下。

The most important difference for your case is that the interface orientation is never face up/down.

在您的情况下,您可以向视图控制器询问当前的用户界面方向: self.interfaceOrientation

In your case you can just ask the view controller for the current user interface orientation: self.interfaceOrientation.

您的情况可能有点像 if(deviceOrientation面朝上/朝下且interfaceOrientation是横向)

请记住,设备方向横向左侧意味着用户界面方向正确。

Bear in mind that a device orientation landscape left means a user interface orientation landscape right.

这篇关于当iphone设备方向朝上/朝下时,我可以判断它是风景还是肖像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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