大佬教程收集整理的这篇文章主要介绍了Objective-C中iOS 6上的强制横向方向,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经看到了其他类似的问题,但它并不适用于我的目的.我创建了一个LandscapeViewController,它是UIViewController的子类,我在这里编写了这些方法:
#pragma mark - Orientation Methods - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } - (BOOL)shouldAutorotate { return YES; }
当我按下详细视图控制器时,这是我的代码:
DetailViewController *detailVC = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; [self.navigationController pushViewController:detailVC animated:YES];
我正在考虑在上面的代码中将我的LandscapeViewController子类化到哪里以使其工作或如何正确地子类化并推送我的详细视图控制器.如果导航控制器无法将我的细节视图控制器从纵向推送到横向,我也可以以模态方式呈现我的详细视图控制器.我在哪里做错了?
我无法在导航控制器中执行此操作.相反,我所做的是从视图A打开模态视图以查看B并强制新的导航控制器进入此视图.
这在iOS5中对我有用.
您需要为导航控制器创建一个类别,如下所示:
UINavigationController Rotation_IOS6.h
#import <UIKit/UIKit.h> @interface UINavigationController (Rotation_IOS6) - (BOOL)shouldAutorotate; - (NSUInteger)supportedInterfaceOrientations; - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation; @end
UINavigationController Rotation_IOS6.h
#import "UINavigationController+Rotation_IOS6.h" @implementation UINavigationController (Rotation_IOS6) - (BOOL)shouldAutorotate { return [self.topViewController shouldAutorotate]; } - (NSUInteger)supportedInterfaceOrientations { return [self.topViewController supportedInterfaceOrientations]; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return [self.topViewController preferredInterfaceOrientationForPresentation]; } @end
在AppDelegate.m中添加:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ return UIInterfaceOrientationMaskAll; }
然后在视图A中:
- (BOOL)shouldAutorotate { return YES; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPorTrait | UIInterfaceOrientationMaskPorTraitUpsideDown; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPorTrait; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPorTrait || interfaceOrientation == UIInterfaceOrientationPorTraitUpsideDown); }
同样在View A中打开View B执行此操作:
ViewB *vc = [[ViewB alloc] initWithNibName:@"ViewB" bundle:nil]; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc]; [self presentViewController:navigationController animated:YES completion:nil];
最后,在View B中
- (BOOL)shouldAutorotate { return YES; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeRight; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft); }
以上是大佬教程为你收集整理的Objective-C中iOS 6上的强制横向方向全部内容,希望文章能够帮你解决Objective-C中iOS 6上的强制横向方向所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。