dear风会停息 2015-10-27 05:38 采纳率: 13.8%
浏览 2550

IOS中整个工程是设置了支持屏幕旋转,那么如何禁止其中某个视图旋转呢?

如题,整个项目中其他视图都是可以旋转的,但是,现在希望其中一个视图只能保持纵向,不允许旋转。

用什么代码有效?

在要禁止的视图中,加入了下面的代码,无效。

  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

{

return (toInterfaceOrientation == UIInterfaceOrientationPortrait);

}

  • (BOOL)shouldAutorotate

{

return NO;

}

  • (NSUInteger)supportedInterfaceOrientations

{

return UIInterfaceOrientationMaskPortrait;//只支持这一个方向(正常的方向)

}
有哪位好心人有完整的方法,帮帮我,谢谢了

  • 写回答

3条回答 默认 最新

  • Eric博客 2015-10-27 07:50
    关注

    UINavigationController添加一个分类,然后重新构造函数
    #import "UINavigationController+Category.h"

    @implementation UINavigationController (Category)

    • (BOOL)shouldAutorotate {
      return [self.viewControllers.lastObject shouldAutorotate];
      }

    • (NSUInteger)supportedInterfaceOrientations {
      return [self.viewControllers.lastObject supportedInterfaceOrientations];
      }

    • (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
      return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];
      }

    @end

    在需要不旋转的界面中加上,你上述的代码

    评论

报告相同问题?

悬赏问题

  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机