如何在iOS 6中以编程方式获取设备的当前方向? [英] How to get current orientation of device programmatically in iOS 6?

查看:176
本文介绍了如何在iOS 6中以编程方式获取设备的当前方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了iOS应用程序并在iOS6设备上进行了测试。在测试时,我意识到我的应用程序没有按预期响应方向更改。

I have developed an iOS App and tested it on iOS6 device. While testing, I realized that my App is not responding to Orientation changes as expected.

这是我的代码:

// Autorotation (iOS >= 6.0)
- (BOOL) shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskPortrait;
}

准确地说,我想知道在iOS中的方向更改中调用哪些方法。

Precisely, I want to know that what Methods are called on Orientation Changes in iOS.

推荐答案

你可以尝试这个,可以帮助你:

You can try this, may help you out:

如何在iOS 6中以编程方式更改设备方向


OR

OR

Objective-c:

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]

Swift:

if UIDevice.current.orientation.isLandscape {
    // Landscape mode
} else {
    // Portrait mode
}

这篇关于如何在iOS 6中以编程方式获取设备的当前方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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