您的位置:首页 > 产品设计 > UI/UE

【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

@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; }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: