在UINavigationController下只要一个页面支持转屏
来源:互联网 发布:西安行知小学 编辑:程序博客网 时间:2024/05/22 05:32
碰到了问题,搜索了一下。还是谷歌给力
Handling Rotation in iOS6
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.
3 Answers
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;}
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.
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.
3 Answers
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;}
shouldAutorotateToInterfaceOrientation:
when that's a deprecated method? And is "shouldAutoRotate" spelled that way (with upper-case R) in your actual implementation? – Hot Licks Dec 10 '12 at 20:43I 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.
- 在UINavigationController下只要一个页面支持转屏
- 支持一个页面横屏的方法
- 一个B.js获取另一个A.js的方法,只要将在html页面中的载入顺序将A.js放在B.js前即可
- 发现一个在IE下也支持 png 的js
- 支持单一页面可以横屏的一个坑
- 点击页面,UINavigationController…
- UINavigationController和页面间传值
- iOS 一个页面支持一个方向上横屏,其他页面全部竖屏
- 在IE下,页面只有一个text的时候,回车将自动submit(转)
- 用UINavigationController实现在两个页之间导航(下)
- 在UINavigationController下的-(void)viewWillAppear:方法失效的解决办法
- 在没有UINavigationController的情况下,显示状态栏的方法
- 自己真的能搭建一个云盘!只要半个小时!全平台支持!
- 一个将txt转成xls的程序(只是玩而已,这程序没意义,在window只要改下扩展名就好了)
- 只要一个返回语句
- 只要一个返回语句
- 只要一个返回语句
- 在jsp页面下, 让eclipse完全支持HTML/JS/CSS智能提示
- Java读取文件方法大全
- Nexus1.9建立私服自己使用
- 华为第1书:《华为交换机学习指南》全面预售中
- vsto插件在64位Office的一个异常---算术运算溢出(IntPtr转int)
- How to declare a null pointer
- 在UINavigationController下只要一个页面支持转屏
- oracle-0乱七八糟
- 二叉排序树的创建查找与删除
- 《REWORK》启示录 发出你的心声——程序员与身体
- Erlang接触的感受
- jQuery.i18n.properties实现js国际化
- 模拟登陆第一步:教你如何用wireshare抓取学校学籍管理系统登陆信息
- 使用struts2框架提交表单时不能传递到后台的问题
- WINDOWS 如何远程LINUX服务器
shouldAutorotateToInterfaceOrientation:
when that's a deprecated method? And is "shouldAutoRotate" spelled that way (with upper-case R) in your actual implementation? – Hot Licks Dec 10 '12 at 20:43