无论旋转如何锁定方向 [英] Lock orientation regardless of rotation

查看:106
本文介绍了无论旋转如何锁定方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITabBar 应用程序,其中嵌入了 UINavigation ,用于某些视图。在一个特定的导航视图中,我显示图形/图表,最好在 landscape 中显示它们,就像iPhone向左或向右旋转一样。该应用程序的其余部分更适合肖像。所以我想强制包含图形的视图在横向加载,而不管用户如何物理旋转设备。我试过了:

I have a UITabBar application with embedded UINavigation for some of the views. On one specific navigationview I am displaying graphs/charts and it would be better to display them in landscape as if the iPhone was rotated to the left or right. The rest of the app is better suited to portrait. So I want to "force" the views containing graphs to load in landscape regardless of how the user has the device physically rotated. I've tried:

#pragma mark - Rotation
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

但这似乎对视图没有任何作用。如果我为目标选择支持的界面方向中的横向左侧图标,则它允许整个应用程序在设备旋转时重新定向。有没有办法以纵向方式锁定我的应用程序以获取所有普通视图,并锁定横向以查看包含图形的视图,以便应用程序忽略实际的设备方向?

But this does not seem to do anything to the view. If I select the "Landscape Left" icon in the "Supported Interface Orientations" for my target then it allows the entire app to re-orientate on rotation of the device. Is there a way to lock my app in portrait for all normal views and lock in landscape for my views containing graphs such that the app ignores the actual device orientation?

推荐答案

首先我使用的是iOS 6 SDK。

Firstly I am using iOS 6 SDK.

我正在使用自定义TabBar控制器。
并通过以下代码集控制TabBar控制器的方向

I am using a custom TabBar Controller. and controlling the orientation of that TabBar Controller by the below set of codes

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // You do not need this method if you are not supporting earlier iOS Versions
    return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

- (NSUInteger)supportedInterfaceOrientations
{
    return [self.selectedViewController supportedInterfaceOrientations];
}

- (BOOL)shouldAutorotate
{
    return YES;
}

视图控制器应包含

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
    return UIInterfaceOrientationIsLandscape(orientation);
}

这就是我所做的,并且能够将视图锁定为横向或纵向(在我的情况下)。要强制,您可以设置警报视图,说明用户将设备转为横向并向他显示图表。只是一个建议。

This is what I did and was able to lock a view to landscape or portrait (in my case). To force may be you can put a alert view stating the user to turn the device to landscape and show him the graph. Just a suggestion.

这篇关于无论旋转如何锁定方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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