Xcode iphone定向支持某些视图 [英] Xcode iphone orientation support for certain views

查看:138
本文介绍了Xcode iphone定向支持某些视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了主视图控制器之外,我想支持所有视图的所有方向。我似乎找不到办法做到这一点。

I want to support all orientations for all views except for the main view controller. I can't seem to find a way to do that.

我可以支持所有视图的方向或整个应用程序中没有视图。如何在整个应用程序中支持某些视图的方向?

I can either support orientation for all views or no views throughout the app. How do you support orientations for certain views throughout the app?

推荐答案

将最顶层的控制器子类化。
例如,你有一个导航控制器作为最顶层的控制器,那么你只需要
子类 UINavigationController 并在.m中编写以下代码行子类的文件

Subclass the top most controller . For example you have a navigation controller as the top most controller then you just need to subclass UINavigationController and write the following line of code in .m file of the subclass

- (BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

现在覆盖方法 - (BOOL)shouldAutorotate 为项目中的每个控制器。
为那些你需要轮换的控制器返回 TRUE 并为那些控制器返回 FALSE 你不需要轮换。

Now overwrite the method - (BOOL)shouldAutorotate for each of the controllers in your project. Return TRUE for those controller for which you need to do rotation and Return FALSE for those controller for which you dont need to do rotation .

干杯!!!!!

这篇关于Xcode iphone定向支持某些视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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