如何只允许单个 UIViewController 在横向和纵向方向上旋转? [英] How to allow only single UIViewController to rotate in both Landscape and Portrait direction?

查看:19
本文介绍了如何只允许单个 UIViewController 在横向和纵向方向上旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用仅适用于 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" ,我想同时支持 landscapeportrait 模式.

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;
}

但它无法旋转那个视图.

But it could not rotate that view.

我为此搜索了很多,但无法找到解决我的问题的方法.

I have searched a lot for this , but could not be able to find the solution for my issue.

而且在ChatView"中还有一些对象,如按钮、文本字段,其框架以编程方式设置.所以我想知道我是否还必须为横向模式设置所有这些对象的框架?

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?

请帮帮我.

谢谢.....

推荐答案

我认为如果您只想支持一个视图控制器旋转,这是不可能的,因为应用程序将遵循您在 .plist 文件.您可以遵循的替代方法是支持您的应用横向和纵向,将所有视图控制器的旋转冻结为纵向,聊天视图除外.

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,请创建一个名为例如的新文件.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

在主类 xib 中将 UINavigationController 的类设置为 CustomNavigationController.希望对你有帮助..

Set the class of your UINavigationController in your main class xib as CustomNavigationController. Hope it helps ypu..

这篇关于如何只允许单个 UIViewController 在横向和纵向方向上旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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