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];
相关新闻>>
- 发表评论
-
- 最新评论 更多>>
今日头条
更多>>您可能感兴趣的文章
- iPhone开发学习笔记006—— NSNotification自定义通知名
- Android:实现TabWidget选项卡按钮在屏幕下方
- ios学习笔记(二)xcode 4.3.2下实现基本交互
- Lexical or Preprocessor Issue 'xxx.h
- ios开发问题:添加库和复制其它工程文件编译错误问题
- iphone开发之object c基础一定义接口
- Memory on the iPhone
- iPhone应用开发之十一:常用的三种动画表现效果
- 多线程之NSInvocationOperation
- (iPhone/iPad开发)presentViewController相应方法在SDK5.0前后