设备方向没有得到。 [英] Device Orientation not getting.

查看:109
本文介绍了设备方向没有得到。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在研究IOS 7,我的问题是我无法在ViewDidLoad方法中获取当前设备的方向。

Currently i am working on IOS 7 and my problem is i am not able to get orientation of current device in ViewDidLoad method.

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskAll);

}
- (void)viewDidLoad
{
    [super viewDidLoad];

    if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)){
        NSLog(@"i am in landscape mode");
    }
    if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)){
        NSLog(@"i am in portrait mode");
    }
}

我在 FirstViewController.m ,当我运行我的应用程序时,没有任何条件成为现实,
任何人都可以帮助我为什么没有条件变为真,即使我在纵向模式下运行我的应用程序。
提前致谢。

I write this code in my FirstViewController.m,and when i run my application no condition become true out of them, can anybody help me why no condition become true even i run my application in portrait mode. Thanks in advance.

推荐答案

试试这个。

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

if(UIInterfaceOrientationIsLandscape(orientation)) {
    //Landscape mode
}
else
{
    //Portrait mode
}

编辑:使用 UIInterfaceOrientationIsLandscape UIInterfaceOrientationIsPortrait 查找方向模式的方法

这篇关于设备方向没有得到。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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