• ios 单个ViewController屏幕旋转


    如果需要旋转的ViewController 使用了UINavigationController,对UINavigationController进行如下扩展

    @implementation UINavigationController(shouldAutorotate)
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); }
    - (BOOL)shouldAutorotate { return self.topViewController.shouldAutorotate; }
    - (NSUInteger)supportedInterfaceOrientations { return self.topViewController.supportedInterfaceOrientations; } @end

    需要旋转的ViewController设置

     - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
        return YES;
    }
    
    - (BOOL)shouldAutorotate
    {
        return YES;
    }
    
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskAll;
    }

    其他不需要旋转的 ViewController设置,建议添加BaseViewController统一控制

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    - (BOOL)shouldAutorotate
    {
        return NO;
    }
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationPortrait;
    }
  • 相关阅读:
    一些概念理解(持续更新)
    python练习题
    linux常用命令
    数据库索引的一点学习(待更新)
    sql注入的一点学习(待更新)
    python 选择排序的实现
    python 冒泡排序的实现
    1--初始配置
    0--HttpUrlConnection 基础知识
    1--HTTP基础知识
  • 原文地址:https://www.cnblogs.com/geweb/p/shouldAutorotate.html
Copyright © 2020-2023  润新知