zoukankan      html  css  js  c++  java
  • iOS支持横屏旋转, 常规方法和强制选择

    横屏支持

    常规方法支持旋转

    // controller的内容是否支持自动旋转
    - (BOOL)shouldAutorotate
    {
        return YES;
    }
    1. 模拟器iOS7.1 : 转横屏时,被调用;横屏转竖屏,也被调用。

    2. 模拟器iOS8.0 : 转横屏时,被调用;横屏转竖屏,不被调用。

    3. 模拟器iOS9.0 : 转横屏时,被调用;横屏转竖屏,也被调用。

      http://stackoverflow.com/questions/26503423/shouldautorotate-behavior-in-ios-8 

    // controller支持的所有用户界面方向
    - (UIInterfaceOrientationMask)supportedInterfaceOrientations
    {
      return UIInterfaceOrientationMaskAll;
    }
    当用户改变设备方向,系统会调用root view controller 或者显示的view controller的这个方法。如果view controller支持新方向,window和view controller会旋转到新的方向。当shouldAutorotate设置为NO的时候,此方法不被调用。
    // 展示view controller时的方向
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
      return UIInterfaceOrientationPortrait;
    }
    全屏展示view controller时,系统会调用此方法,优先根据你设置的方向设置view controller的方向。

    如果不实现该方法,系统会根据当前status bar的方向,确定view controller的方向。

    强制设置orientation属性值

    官网上orientation 是只读属性。我们无法直接改写它的值。但是

    iOS5 之前:setOrientation可以改变orientation属性的值。

    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

      然而iOS6 之后,此方法被弃用,不过我们还可以用下面方法强置屏幕方向。

    [[UIDevice currentDevice] setValue:
                          [NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
                                forKey:@"orientation"];

    其实下面,这两个方法,可以获取或设置任意对象的属性:
    -(id)valueForKey:(NSString *)k;
    -(void)setValue:(id)v forKey:(NSString *)k;

    这是KVC(键值编码)是通过一系列定义在NSObject中的方法实现的,我们可以通过属性的名称存取属性的值。

    http://stackoverflow.com/questions/18035992/objective-c-setvalueforkey-on-c-primitive-types

    https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/KeyValueCoding/Articles/BasicPrinciples.html

  • 相关阅读:
    4.23上机练习
    4.17java作业
    4.16java作业
    leetcode 189
    leetcode 172
    leetcode 171
    leetcode 169
    win10内网外网智能访问
    leetcode 168
    leetcode 165
  • 原文地址:https://www.cnblogs.com/sueZheng/p/4971866.html
Copyright © 2011-2022 走看看