我的应用程序只支持iphone台设备(包括iphone 4和5),并且只支持ios 6台.

我的整个应用程序只支持portrait模式.但是有一个叫做"ChatView"的视图,我想支持landscapeportrait模式.

我已按如下方式设置了所需的设备旋转-

在此处输入图像描述

我还try 了以下代码来支持"聊天视图"中的旋转-

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

但它无法旋转该视图.

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

在"聊天视图"中还有一些对象,比如按钮、文本字段,它们的框架是按程序设置的.所以我想知道,我是否也应该为风景模式设置所有这些对象的帧?

请帮帮我.

谢谢

推荐答案

我认为,如果您只想支持一个viewcontroller旋转,这是不可能的,因为应用程序将遵循您在.plist文件中设置的方向.另一种方法是支持应用程序的横向和纵向,将除聊天视图外的所有ViewController旋转冻结为纵向.

EDIT

要创建子类UINavigationController,请创建一个名为CustomNavigationController的新文件,并使其成为子类UINavigationController.

.h file

#import <UIKit/UIKit.h>

@interface CustomNavigationController : UINavigationController

@end

.m file

#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.希望对ypu有帮助..

Objective-c相关问答推荐

NSNumberFormatter 和 'th' 'st' 'nd' 'rd' (序数)数字结尾

如何在运行时向对象添加属性?

Asihttprequest 61 错误

pathForResource 返回 null

滚动 NSScrollView 时的回调?

额外的 75 秒从何而来?

UITableView - Select 了哪一行?

实现 -hash / -isEqual: / -isEqualTo...: 用于 Objective-C 集合

Crashlytics iOS - 记录捕获的异常

iOS - 从应用程序获取 CPU 使用率

对块进行类型定义是如何工作的

ios 11 UITabBar UITabBarItem 定位问题

在 Objective C 中,你能判断一个对象是否具有特定的属性或消息吗?

仅在 UIView 顶部的圆角

IOS 6强制设备方向为横向

如何修复UIPopoverController 已弃用警告?

从带有参数的方法名称创建 Select 器

UICollectionView 断言失败

使用正则表达式查找/替换 NSString 中的子字符串

Unwind Segue 在 iOS 8 中不起作用