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

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

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

    评论

报告相同问题?