iOS 7.仅为一个视图控制器更改页面方向

iOS 7.仅为一个视图控制器更改页面方向,第1张

概述我有iPhone应用程序,只支持纵向方向.我想添加到仅支持横向方向的项目视图控制器?可能吗?如果是的话我怎么能实现呢? 我试图像这样包装类别文件: @implementation UINavigationController (Rotation_IOS7)-(BOOL)shouldAutorotate { return YES; } -(NSUIn 我有iPhone应用程序,只支持纵向方向.我想添加到仅支持横向方向的项目视图控制器?可能吗?如果是的话我怎么能实现呢?

我试图像这样包装类别文件:

@implementation UINavigationController (Rotation_IOS7)-(BOol)shouldautorotate    {        return YES;    }    -(NSUInteger)supportedInterfaceOrIEntations    {      return UIInterfaceOrIEntationMaskLandscape;    }

如果我这样做,我会收到此错误:
由于未捕获的异常而终止应用程序UIApplicationInvalIDInterfaceOrIEntation,原因:支持的方向与应用程序没有共同的方向,并且shouldautorotate返回YES

解决方法 我试过这个并且它有效: http://www.sebastianborggrewe.de/only-make-one-single-view-controller-rotate/

首先,将这些代码添加到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.仅为一个视图控制器更改页面方向所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1069038.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存