如何只允许单个UIViewController沿横向和纵向旋转?

我的应用仅适用于iphone设备(iphone 4和5),并且仅支持ios 6。


我的整个应用仅支持portrait模式。但是有一个名为“ ChatView”的视图,我想同时支持landscape和portrait模式。


我已将所需的设备旋转设置如下:

http://img.mukewang.com/5db7a9420001102c06360145.jpg

我还尝试了以下代码来支持“ ChatView”中的旋转-


-(BOOL)shouldAutorotate

{

    return YES;

}


-(NSUInteger)supportedInterfaceOrientations

{

    return UIInterfaceOrientationMaskLandscape;

}

但是它无法旋转该视图。


我为此进行了很多搜索,但找不到我的问题的解决方案。


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


请帮我。


谢谢.....


神不在的星期二
浏览 441回答 3
3回答

慕姐8265434

简单,但效果很好。iOS 7.1和8AppDelegate.h@property () BOOL restrictRotation;AppDelegate.m-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{if(self.restrictRotation)    return UIInterfaceOrientationMaskPortrait;else    return UIInterfaceOrientationMaskAll;}ViewController-(void) restrictRotation:(BOOL) restriction{    AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;    appDelegate.restrictRotation = restriction;}viewDidLoad[self restrictRotation:YES]; or NO

三国纷争

您的视图控制器将永远不会旋转到应用程序本身不支持的任何位置。您应该启用所有可能的旋转,然后在不应旋转的视图控制器中放入以下行- (UIInterfaceOrientationMask)supportedInterfaceOrientations{    return UIInterfaceOrientationMaskPortrait;}在ChatView中,应为:- (UIInterfaceOrientationMask)supportedInterfaceOrientations{    return UIInterfaceOrientationMaskAll;}如果您需要在轮换之后更改布局,则应对子视图进行适当的更改- (void)viewWillLayoutSubviews使用self.view.bounds检查的电流的大小view,因为self.view.frame旋转后也不会改变。
打开App,查看更多内容
随时随地看视频慕课网APP