如何只允许单个UIViewController在横向和纵向方向上旋转? [英] How to allow only single UIViewController to rotate in both Landscape and Portrait direction?
问题描述
我的应用仅适用于 iphone
设备(iphone 4和5)并且仅支持 ios 6
。
My app is only for iphone
device (both iphone 4 and 5) and built to support only ios 6
.
我的整个应用程序仅支持 portrait
模式。但有一个名为 ChatView
的视图,我想支持 landscape
和肖像
模式。
My whole app only supports portrait
mode. But there is one view called "ChatView
" , which i want to support both landscape
and portrait
modes.
我已设置所需的设备轮换如下 -
I have set the required device rotations as follows -
我还尝试使用以下代码来支持ChatView中的旋转 -
I have also tried following code to support rotation in "ChatView" -
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
但它无法旋转该视图。
我已经搜索了很多,但无法找到我的问题的解决方案。
I have searched a lot for this , but could not be able to find the solution for my issue.
还有ChatView那里是一些对象,如按钮,文本框架,其框架设置为programmaticaly。所以我想知道我是否必须为横向模式设置所有这些对象的帧?
And also in "ChatView" there are some objects like buttons, textfields whose frames are set programmaticaly. So i want to know should i have to set frames of all those objects for landscape mode also?
请帮帮我。
谢谢......
推荐答案
我想如果你只想支持一个viewcontroller轮换,那就不是可能因为应用程序将遵循您在 .plist
文件中设置的方向。您可以遵循的替代方案是支持您的应用程序的横向和纵向,冻结所有viewcontrollers旋转到纵向,聊天视图除外。
I think if you want to support just one viewcontroller rotation, it is not possible since application will follow orientations set by you in .plist
file. An alternate you can follow is to support your app for both landscape and portrait, freeze all viewcontrollers rotation to portrait except for chat view.
编辑
要子类化 UINavigationController
,请创建一个名为eg的新文件 CustomNavigationController
并使其成为 UINavigationController的子类
。
To subclass UINavigationController
, create a new file with name e.g. CustomNavigationController
and make it subclass of UINavigationController
.
.h文件
#import <UIKit/UIKit.h>
@interface CustomNavigationController : UINavigationController
@end
.m文件
#import "CustomNavigationController.h"
@interface CustomNavigationController ()
@end
@implementation CustomNavigationController
-(BOOL)shouldAutorotate
{
return NO;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
@end
设置<的等级 UINavigationController
在主类xib中为 CustomNavigationController
。希望它有助于ypu ..
Set the class of your UINavigationController
in your main class xib as CustomNavigationController
. Hope it helps ypu..
这篇关于如何只允许单个UIViewController在横向和纵向方向上旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!