
在这个简单的场景中,我有一个只包含UINavigationController和一个初始视图控制器的storyboard:
看过有关IOS 6中自动旋转方法更改的所有帖子,我创建了UINavigationController的子类,并在这个子类和第一个视图控制器上实现了shouldautorotate和supportedInterfaceOrIEntations方法:
导航控制器:
// NavController.h#import <UIKit/UIKit.h>@interface NavController : UINavigationController@end// NavController.m#import "NavController.h"@interface NavController ()@end@implementation NavController- (BOol) shouldautorotate { return YES;}- (NSUInteger) supportedInterfaceOrIEntations { return UIInterfaceOrIEntationMaskAll;}@end 第一控制器
// FirstController.h#import <UIKit/UIKit.h>@interface FirstController : UIVIEwController@end// FirstController.m#import "FirstController.h"@interface FirstController ()@end@implementation FirstController- (voID)vIEwDIDLoad{ [super vIEwDIDLoad]; // Do any additional setup after loading the vIEw.}- (BOol)shouldautorotate { return YES;}- (NSUInteger)supportedInterfaceOrIEntations { return UIInterfaceOrIEntationMaskAll;}@end 项目设置指定应支持所有旋转:
这些似乎都没有任何影响……!当我在模拟器中运行时,我得到:
请..!我在这里错过了什么?这真让我抓狂!我想至少让这个简单的案例工作,所以我希望能让我的相当大的应用程序工作!
解决方法 如果您计划为所有视图控制器启用或禁用旋转,则不需要子类化UINavigationController.而是使用:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrIEntationsForWindow:(UIWindow *)window
在你的AppDelegate中.
如果您计划在应用程序中支持所有方向但在父视图控制器(UINavigationController堆栈)上支持不同的方向,则应使用
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrIEntationsForWindow:(UIWindow *)window
与父视图控制器中的以下方法结合使用.
- (BOol)shouldautorotate
和
- (NSUInteger)supportedInterfaceOrIEntations
但是如果您打算在同一个导航堆栈(例如我)中的不同Children VIEwControllers中使用不同的方向设置,则需要检查导航堆栈中的当前VIEwController.
我在UINavigationController子类中创建了以下内容:
- (BOol)shouldautorotate{ return YES;}- (NSUInteger)supportedInterfaceOrIEntations{ int interfaceOrIEntation = 0; if (self.vIEwControllers.count > 0) { ID vIEwController; DLog(@"%@",self.vIEwControllers); for (vIEwController in self.vIEwControllers) { if ([vIEwController isKindOfClass:([InitialUseVIEwController class])]) { interfaceOrIEntation = UIInterfaceOrIEntationMaskPortrait | UIInterfaceOrIEntationMaskPortraitUpsIDeDown; } else if ([vIEwController isKindOfClass:([MainVIEwController class])]) { interfaceOrIEntation = UIInterfaceOrIEntationMaskPortrait | UIInterfaceOrIEntationMaskPortraitUpsIDeDown; } else { interfaceOrIEntation = UIInterfaceOrIEntationMaskAllButUpsIDeDown; } } } return interfaceOrIEntation;} 由于您无法再控制子VIEwControllers所呈现的视图控制器的旋转设置,您必须以某种方式拦截视图控制器当前在导航堆栈中的内容.这就是我做的:).希望有所帮助!
总结以上是内存溢出为你收集整理的cocoa – 在iOS 6上使用故事板处理方向/旋转全部内容,希望文章能够帮你解决cocoa – 在iOS 6上使用故事板处理方向/旋转所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)