zoukankan      html  css  js  c++  java
  • iOS横屏设置的几种方式

    1.界面旋转,MainScreen的宽高不变,键盘位置不变

    CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;
    
    [UIView beginAnimations:nil context:nil];
    
    [UIView setAnimationDuration:duration];
    
    self.view.transform =CGAffineTransformMakeRotation(M_PI/2);
    
    [UIView commitAnimations];
    

     2.界面旋转,MainScreen的宽高改变,键盘位置不变

    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
    
            SEL selector = NSSelectorFromString(@"setOrientation:");
    
            NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
    
            [invocation setSelector:selector];
    
            [invocation setTarget:[UIDevice currentDevice]];
    
            int val = UIInterfaceOrientationLandscapeRight;
    
            [invocation setArgument:&val atIndex:2];
    
            [invocation invoke];
    }

    3.界面旋转,MainScreen的宽高改变,键盘位置改变

    a.General—>中勾选Lnadscape Left/Lnadscape Right,默认是勾选上了的

    b.控制器中实现以下两个方法:

    // 支持设备自动旋转
    - (BOOL)shouldAutorotate
    {
        return YES;
    }
    
    /**
     *  设置特殊的界面支持的方向,这里特殊界面只支持Home在右侧的情况
     */
    - (UIInterfaceOrientationMask)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskLandscapeRight;
    }

     PS:如何判断当前是否横屏,一下3个方法都可以

        self.interfaceOrientation(iOS 2.0~8.0)

          [UIApplication sharedApplication] statusBarOrientation]

          [[UIDevice currentDevice] orientation]

  • 相关阅读:
    面经
    Onedrive云盘程序——OneManager小白设置指南
    Docker 命令
    Linux 命令
    Spring boot 返回参数移除null属性
    Springboot
    正则
    JVM内存模型
    缓冲和缓存的区别
    SpringBoot如何优雅的将静态资源配置注入到工具类中
  • 原文地址:https://www.cnblogs.com/liuluoxing/p/6482983.html
Copyright © 2011-2022 走看看