iOS项目配置不支持屏幕旋转,配置指定单页面支持屏幕旋转

在UIApplication实现该方法:

1.重写AppDelegate中的 supportedInterfaceOrientationsForWindow方法,该方法可以配置单个页面是否支持屏幕旋转。

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

    UIViewController*result =nil;

    result = [selfgetCurrentVC];

    if ([result isKindOfClass:[xxxViewController class]]) {

        return UIInterfaceOrientationMaskAll;

    }else{

        return UIInterfaceOrientationMaskPortrait;

    }

}

2.实现获取当前屏幕正在展示的controller,用于判断当前屏幕正在展示的controller是否支持屏幕旋转

-(UIViewController *)getCurrentVC

{

    UIWindow *window = [UIApplication sharedApplication].delegate.window;

      if (window.windowLevel != UIWindowLevelNormal) {

          NSArray*windows = [[UIApplicationsharedApplication]windows];

          for(UIWindow* tmpWininwindows) {

              if(tmpWin.windowLevel==UIWindowLevelNormal) {

                  window = tmpWin;

                  break;

              }

          }

      }

      UIViewController*rootVC = window.rootViewController;

      UIViewController*activeVC =nil;


      while(true) {

          if([rootVCisKindOfClass:[UINavigationControllerclass]]) {

              activeVC = [(UINavigationController*)rootVCvisibleViewController];

          }elseif([rootVCisKindOfClass:[UITabBarControllerclass]]) {

              activeVC = [(UITabBarController*)rootVCselectedViewController];

          }elseif(rootVC.presentedViewController) {

              activeVC = rootVC.presentedViewController;

          }elseif(rootVC.childViewControllers.count>0) {

              activeVC = [rootVC.childViewControllerslastObject];

          }else{

              break;

          }

          rootVC = activeVC;

      }

      returnactiveVC;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 更新到13.5后,发现获取当前vc时,获取到的竟然是window。 以下是两种解决方案: 第一种: UIWindo...
    陈不同阅读 8,983评论 0 6
  • 在简单项目中,有使用到apns推送服务,许多文章有涉及到却没有讲清楚。最近做福路通项目,有使用到,做一个总结。 推...
    天空的守望者阅读 4,383评论 0 3
  • 由于项目中经常遇到这些坑,所以在这里做一下汇总,方便以后遇到是查阅,顺便也分享给大家,共同进步。 1. 修改导航栏...
    Luke_Hu阅读 1,300评论 0 0
  • 获取当前视图控制器 (UIViewController *)currentViewController {UIVi...
    可乐小子阅读 3,720评论 0 1
  • 久违的晴天,家长会。 家长大会开好到教室时,离放学已经没多少时间了。班主任说已经安排了三个家长分享经验。 放学铃声...
    飘雪儿5阅读 12,186评论 16 22