• Iphone和iPad适配, 横竖屏


    竖屏情况下: [UIScreen mainScreen].bounds.size.width = 320

    [UIScreen mainScreen].bounds.size.width = 568

    横屏情况下:

     [UIScreen mainScreen].bounds.size.width = 568

     [UIScreen mainScreen].bounds.size.height = 320

    UIViewController 和 UIWindow同理

     

    1. storyboard iphone和 iPad版

    即为iphone和ipad分别创建xib/storyboard文件

    Main_iPhone.storyboard

    Main_iPad.storyboard

    横竖屏

    苹果官方文档:

    When the user changes the device orientation, the system calls this method on the root view controller or the topmost presented view controller that fills the window. If the view controller supports the new orientation, the window and view controller are rotated to the new orientation. This method is only called if the view controller'€™s shouldAutorotate method returns YES.

    - (BOOL)shouldAutorotate
    
    {   
      
    return YES; } - (NSUInteger)supportedInterfaceOrientations {   return UIInterfaceOrientationMaskAll; }

    注意要写在最顶层视图控制器, (self.window.rootViewController) , 否则不会进入以上方法

    而且

    supportedInterfaceOrientations的返回值必须是

    UIInterfaceOrientationMaskLandscapeLeft 或者 UIInterfaceOrientationMaskLandscapeRight 或者...

    总之必须加Mask

     通知是当前线程异步

    tabbarcontroller 为 根控制器的情况

    - (BOOL)shouldAutorotate
    {
        return [self.selectedViewController shouldAutorotate];
    }
    
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return [self.selectedViewController preferredInterfaceOrientationForPresentation];
    }
    
    
    - (NSUInteger)supportedInterfaceOrientations
    {
        return [self.selectedViewController supportedInterfaceOrientations];
    }

    navigationcontroller为根控制器的情况:

    - (BOOL)shouldAutorotate
    {
        return [self.viewControllers.lastObject shouldAutorotate];
    }
    
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];
    }
    
    
    - (NSUInteger)supportedInterfaceOrientations
    {
        return [self.viewControllers.lastObject supportedInterfaceOrientations];
    }
  • 相关阅读:
    sql批量插入数据测试
    服务器远程桌面连接显示内存不足无法完成解决
    SQL Server 2008 R2占用内存越来越大两种解决方法
    .net core 用引用log4net 写入日志
    用vscode开发,建议安装的插件大全
    关于如何添加windows的性能计数器
    VScode创建Vue项目,报错:vue : 无法加载文件 C:UsersxxxAppDataRoaming pmvue.ps1
    EFCore-脚手架Scaffold发生Build Failed问题的终极解决
    springboot 事务回滚
    JDK11.0.7下载及安装详细教程(win10)
  • 原文地址:https://www.cnblogs.com/apem/p/4427328.html
Copyright © 2020-2023  润新知