UINavigationController – > RootVIEwController(UIVIEwController) – > UItableVIEwController – > DetailVIEwController(UIVIEwController)
我想将RootVIEwController上的方向锁定到“仅”纵向,但为其余视图控制器留下所有方向.
如果我把它放到子类UINavigationController中:
- (BOol)shouldautorotatetoInterfaceOrIEntation:(UIInterfaceOrIEntation)interfaceOrIEntation{ // Return YES for supported orIEntations return (interfaceOrIEntation == UIInterfaceOrIEntationPortrait);}-(NSUInteger)supportedInterfaceOrIEntations{ return UIInterfaceOrIEntationMaskPortrait;}
所有视图控制器然后被锁定到纵向.
我的问题是,有没有办法只将RootVIEwController锁定到纵向,但是为其他视图控制器留下所有选项?
解决方法 检查在这里链接修复自动转换在iOS 6和设置方向支持每视图基础: http://www.disalvotech.com/blog/app-development/iphone/ios-6-rotation-solution/这是你可以做的:
>在.m文件中创建一个作为UINavigationController子类的自定义导航控制器:
- (BOol)shouldautorotate { return self.topVIEwController.shouldautorotate; } - (NSUInteger)supportedInterfaceOrIEntations { return self.topVIEwController.supportedInterfaceOrIEntations; }
>在AppDelegate.h中,
@interface AppDelegate : UIResponder <UIApplicationDelegate> { UINavigationController *navigationController; VIEwController *vIEwController; } @property (strong,nonatomic) UIWindow *window; @property (strong,nonatomic) VIEwController *vIEwController;
在AppDelegate.m中,
- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // set initial vIEw self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; vIEwController = [[VIEwController alloc] initWithNibname:@"RootVIEwController" bundle:nil]; navigationController = [[CustomNavigationController alloc] initWithRootVIEwController:vIEwController]; // iOS 6 autorotation fix [navigationController setNavigationbarHIDden:YES animated:NO]; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; [self.window setRootVIEwController:navigationController]; // iOS 6 autorotation fix //[self.window addSubvIEw:navigationController.vIEw]; [self.window makeKeyAndVisible]; return YES; } - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrIEntationsForWindow:(UIWindow *)window // iOS 6 autorotation fix { return UIInterfaceOrIEntationMaskAll; }
>在您的rootVIEwController中,无论什么事件推动第二个视图控制器,请执行以下 *** 作:
- (IBAction)pushSecondVIEwController:(ID)sender { // push second vIEw controller SecondVIEwController *secondVIEwController = [[SecondVIEwController alloc] initWithNibname:@"SecondVIEwController" bundle:nil]; [self.navigationController pushVIEwController:secondVIEwController animated:YES]; }
>在你的每个视图控制器,添加
- (BOol)shouldautorotate{} - (NSUInteger)supportedInterfaceOrIEntations{}
对于iOS 6,您可以设置每个视图控制器,无论您想要单独的方向支持.
对于iOS 5及更低版本,您可以设置
- (BOol)shouldautorotatetoInterfaceOrIEntation:(UIInterfaceOrIEntation)interfaceOrIEntation{}
所有的学分都转交给John disalvo,他在链接中写了这个示例应用程序.
希望这可以帮助.
总结以上是内存溢出为你收集整理的iphone – ViewController在UINavigationController方向更改全部内容,希望文章能够帮你解决iphone – ViewController在UINavigationController方向更改所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)