ios 6 横竖屏转换
程序的根控制器用了UINavigationController。下面是代码:
1.在appdelegate中添加代码:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskAll;
}
2.给UINavigationController添加个category,在实现文件中添加如下代码:
-(BOOL)shouldAutorotate
{
return [[self topViewController] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self topViewController] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self topViewController] preferredInterfaceOrientationForPresentation];
}
3.在需要横屏的地方添加(竖屏可以更换方向):
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeRight; // 可以修改为任何方向
}
-(BOOL)shouldAutorotate{
return YES;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
4.最重要的是:页面之间切换不能用导航控制器切换,必须使用:
[self presentViewController:navigationController animated:YES completion:Nil];
相关新闻>>
- 发表评论
-
- 最新评论 更多>>