【iOS】ios6.0 UINavigationController支持屏幕自动旋转
2013-06-14 16:36
357 查看
问题描述:
当从页面A跳转到页面B时,使用的是UINavigationController的presentViewController:animated:completion:方法。如果页面A是纵向UI,而页面B则在xib配置中是横向UI,不论在B的viewController实现文件中如何设置,从A到B跳转后,B为纵向显示,无法受其控制。
原因:
猜测是因为presentViewController:animated:completion:时,旋转控制权在parentViewController上,B页面无法拿到控制权。
解决方案:
重写UINavigationController的旋转方法,使viewController能够拿到旋转权。
代码如下:
UINavigationController+Rotation_IOS6.h
UINavigationController+Rotation_IOS6.m
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
当从页面A跳转到页面B时,使用的是UINavigationController的presentViewController:animated:completion:方法。如果页面A是纵向UI,而页面B则在xib配置中是横向UI,不论在B的viewController实现文件中如何设置,从A到B跳转后,B为纵向显示,无法受其控制。
原因:
猜测是因为presentViewController:animated:completion:时,旋转控制权在parentViewController上,B页面无法拿到控制权。
解决方案:
重写UINavigationController的旋转方法,使viewController能够拿到旋转权。
代码如下:
UINavigationController+Rotation_IOS6.h
@interface UINavigationController (Rotation_IOS6) -(BOOL)shouldAutorotate; -(NSUInteger)supportedInterfaceOrientations; -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation; @end
UINavigationController+Rotation_IOS6.m
@implementation UINavigationController (Rotation_IOS6) -(BOOL)shouldAutorotate { return [[self.viewControllers lastObject] shouldAutorotate]; } -(NSUInteger)supportedInterfaceOrientations { return [[self.viewControllers lastObject] supportedInterfaceOrientations]; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; } @end
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
相关文章推荐
- ios6.0 UINavigationController、UITabBarController 支持屏幕自动旋转问题
- 是否支持屏幕旋转 - iOS
- ios6.0之后单个屏幕旋转,不用根视图以及Application windows are expected to have a root view controller at the end of
- iOS手动和自动旋转屏幕
- iOS 5.1及6.0 屏幕旋转的兼容问题
- IOS Orientation, 想怎么转就怎么转~~~ 此博文主要针对IOS应用, 是屏幕旋转相关问题的一个总结. 主要内容有: IOS5,6,7不同版的适配. 强制旋转和自动旋转.
- [iOS]技巧集锦:UICollectionView在旋转屏幕后Cell中的约束不起作用或自动布局失效
- iOS 屏幕旋转 手动和自动
- iOS手动旋转屏幕、自动旋转屏幕
- 转载 -- IOS成长之路-关于iOS6.0 屏幕旋转的问题
- IOS成长之路-关于iOS6.0 屏幕旋转的问题
- 关于iOS6.0 屏幕旋转的问题
- IOS屏幕旋转详解(自动旋转、手动旋转、兼容IOS6之前系统)
- ios某一个屏幕支持旋转,其他不支持的方法
- Cocoa Touch 入门记——《精通 iOS 开发》学习心得(2) [iOS 7(Xcode 5)中的屏幕旋转与自动布局]
- iOS 的Viewcontroller只支持一个屏幕方向,弹出不同方向,旋转
- ios 6.0 屏幕旋转问题
- 根据系统是否支持自动旋转设置屏幕方向
- IOS成长之路-关于iOS6.0 屏幕旋转的问题
- UIWebView中视频播放屏幕自动旋转,app不支持旋转但是某一个页面需要旋转等