
我试图像这样包装类别文件:
@implementation UINavigationController (Rotation_IOS7)-(BOol)shouldautorotate { return YES; } -(NSUInteger)supportedInterfaceOrIEntations { return UIInterfaceOrIEntationMaskLandscape; } 如果我这样做,我会收到此错误:
由于未捕获的异常而终止应用程序UIApplicationInvalIDInterfaceOrIEntation,原因:支持的方向与应用程序没有共同的方向,并且shouldautorotate返回YES
首先,将这些代码添加到AppDelegat类中.
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrIEntationsForWindow:(UIWindow *)window {// Get topmost/visible vIEw controllerUIVIEwController *currentVIEwController = [self topVIEwController];// Check whether it implements a dummy methods called canRotateif ([currentVIEwController respondsToSelector:@selector(canRotate)]) { // Unlock landscape vIEw orIEntations for this vIEw controller return UIInterfaceOrIEntationMaskAllButUpsIDeDown;}// Only allow portrait (standard behavIoUr)return UIInterfaceOrIEntationMaskPortrait;}- (UIVIEwController*)topVIEwController { return [self topVIEwControllerWithRootVIEwController:[UIApplication sharedApplication].keyWindow.rootVIEwController];}- (UIVIEwController*)topVIEwControllerWithRootVIEwController:(UIVIEwController*)rootVIEwController { if ([rootVIEwController isKindOfClass:[UITabbarController class]]) { UITabbarController* tabbarController = (UITabbarController*)rootVIEwController; return [self topVIEwControllerWithRootVIEwController:tabbarController.selectedVIEwController]; } else if ([rootVIEwController isKindOfClass:[UINavigationController class]]) { UINavigationController* navigationController = (UINavigationController*)rootVIEwController; return [self topVIEwControllerWithRootVIEwController:navigationController.visibleVIEwController]; } else if (rootVIEwController.presentedVIEwController) { UIVIEwController* presentedVIEwController = rootVIEwController.presentedVIEwController; return [self topVIEwControllerWithRootVIEwController:presentedVIEwController]; } else { return rootVIEwController; }} 然后,在横向视图控制器中,添加此方法
- (voID)canRotate { } 总结 以上是内存溢出为你收集整理的iOS 7.仅为一个视图控制器更改页面方向全部内容,希望文章能够帮你解决iOS 7.仅为一个视图控制器更改页面方向所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)