在UINavigationController下只要一个页面支持转屏
2013-11-14 17:21
429 查看
碰到了问题,搜索了一下。还是谷歌给力
Handling
Rotation in iOS6
1down votefavorite 3 | I only want to support different Orientations on one View in my UINavigationController Stack. How can I do this? It also has to work in iOS5. objective-c uiviewcontroller uinavigationcontroller orientation ios6
| |||
3 Answers
activeoldestvotesup vote7down voteaccepted | I've had a lot of trouble with how iOS6 handles Orientation, hopefully this is what you're looking for. Create an extension of UINavigationController and call it "UINavigationController+autoRotate". Put this in your UINavigationController+autoRotate.h: #import <UIKit/UIKit.h> @interface UINavigationController (autoRotate) -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation; -(BOOL)shouldAutorotate; - (NSUInteger)supportedInterfaceOrientations; @end Put this in UINavigationController+autoRotate.m: #import "UINavigationController+autoRotate.h" @implementation UINavigationController (autoRotate) -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return [self.topViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; } - (BOOL)shouldAutorotate { return [self.visibleViewController shouldAutorotate]; } - (NSUInteger)supportedInterfaceOrientations { if (![[self.viewControllers lastObject] isKindOfClass:NSClassFromString(@"ViewController")]) { return UIInterfaceOrientationMaskAllButUpsideDown; } else { return [self.topViewController supportedInterfaceOrientations]; } } @end For Views that you DO NOT want to rotate, add: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } - (BOOL)shouldAutorotate { return NO; } And for Views you DO want to rotate: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIDeviceOrientationPortraitUpsideDown); } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAllButUpsideDown; } - (BOOL)shouldAutorotate { return YES; } In your App's delegate, add: - (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window { return UIInterfaceOrientationMaskAllButUpsideDown; }
| ||||||||||||||||||||
comments |
up vote0down vote | I recommend you to NOT create a category on UINavigationController to override those methods. Categories are not aimed to do that, and there is no warranty that your code is going to be loaded instead of Apple's one (even if actually that works). I advise you to create a subclass of UINavigationController, and override those methods in it.
| ||||
|
1down votefavorite 3 | I only want to support different Orientations on one View in my UINavigationController Stack. How can I do this? It also has to work in iOS5. objective-c uiviewcontroller uinavigationcontroller orientation ios6
| |||
3 Answers
activeoldestvotesup vote7down voteaccepted | I've had a lot of trouble with how iOS6 handles Orientation, hopefully this is what you're looking for. Create an extension of UINavigationController and call it "UINavigationController+autoRotate". Put this in your UINavigationController+autoRotate.h: #import <UIKit/UIKit.h> @interface UINavigationController (autoRotate) -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation; -(BOOL)shouldAutorotate; - (NSUInteger)supportedInterfaceOrientations; @end Put this in UINavigationController+autoRotate.m: #import "UINavigationController+autoRotate.h" @implementation UINavigationController (autoRotate) -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return [self.topViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; } - (BOOL)shouldAutorotate { return [self.visibleViewController shouldAutorotate]; } - (NSUInteger)supportedInterfaceOrientations { if (![[self.viewControllers lastObject] isKindOfClass:NSClassFromString(@"ViewController")]) { return UIInterfaceOrientationMaskAllButUpsideDown; } else { return [self.topViewController supportedInterfaceOrientations]; } } @end For Views that you DO NOT want to rotate, add: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } - (BOOL)shouldAutorotate { return NO; } And for Views you DO want to rotate: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIDeviceOrientationPortraitUpsideDown); } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAllButUpsideDown; } - (BOOL)shouldAutorotate { return YES; } In your App's delegate, add: - (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window { return UIInterfaceOrientationMaskAllButUpsideDown; }
| ||||||||||||||||||||
comments |
up vote0down vote | I recommend you to NOT create a category on UINavigationController to override those methods. Categories are not aimed to do that, and there is no warranty that your code is going to be loaded instead of Apple's one (even if actually that works). I advise you to create a subclass of UINavigationController, and override those methods in it.
| ||||
|
相关文章推荐
- 支持单一页面可以横屏的一个坑
- Flex真真的分页,一个页面支持多次复用
- C# PDF Page操作——设置页面切换按钮 C# 添加、读取Word脚注尾注 C#为什么不能像C/C++一样的支持函数只读传参 web 给大家分享一个好玩的东西,也许你那块就用的到
- 用js如何在后台弹出一个新的页面 IE和FF都支持的写法……
- 一个B.js获取另一个A.js的方法,只要将在html页面中的载入顺序将A.js放在B.js前即可
- 还是继续支持标准开发,再送一个页面加入FLASH的通用函数
- UIWebView中视频播放屏幕自动旋转,app不支持旋转但是某一个页面需要旋转等
- webuploader在同一个页面支持多个按钮实例
- 选项卡 一个页面支持多个 表现 结构分离
- js 漂浮广告代码(支持一个页面多次使用,其中一个带关闭功能哦!^^)
- 一个支持Drag页面拖动的组件
- webuploader在同一个页面支持多个按钮实例
- iOS 6.0之后支持一个页面横屏的方法
- MOSS中集成各个子网站的数据到一个页面,做"决策支持"页面的首选: Web Capture
- UIWebView中视频播放屏幕自动旋转,app不支持旋转但是某一个页面需要旋转等
- 自己写的一个PHP面向对象方式的页面生成库(同时支持Web和Wap)
- 一个简化版的SSH后端框架demo,支持接口、页面开发
- 自己真的能搭建一个云盘!只要半个小时!全平台支持!
- 利用线性布局和相对布局实现一个简单的页面并且使应用支持国际化语言
- 选项卡 一个页面支持多个 表现 结构分离