zoukankan      html  css  js  c++  java
  • 关于设置iOS横竖屏的两种方式(转载)

    iPhone的横屏竖屏针对iOS系统版本分为两种开发方式: 一种是iOS 6之前的使用模式 一种是iOS6的新模式. 两者的区别还是蛮大的.

    1:iOS6之前通常使用 shouldAutorotateToInterfaceOrientation 来单独控制某个UIViewController的方向,需要哪个viewController支持旋转,只需要重写shouldAutorotateToInterfaceOrientation方法。如下示例,设置以后,屏幕被旋转时只支持横屏转换:
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation  
    {  
       return UIInterfaceOrientationIsLandscape(interfaceOrientation);  
    }  
     
     
    iOS6之后使用如下两个方法控制自动旋转,分别是:  
    - (BOOL)shouldAutorotate  
    {  
        NSLog(@"让不让我旋转?");  
        return YES;  
    }  
    - (NSUInteger)supportedInterfaceOrientations {  
        NSLog(@"让我旋转哪些方向");  
        return UIInterfaceOrientationMaskAllButUpsideDown;  
    }  
     
     
    那么在自动旋转触发后,系统会自动调用另外两个方法:  
    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {  
        [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];  
        NSLog(@"将要旋转了?");  
    }  
    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {  
        [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];  
        NSLog(@"如果让我旋转,我已经旋转完了!");       
    }  
     
     
    2:让程序第一次启动时立刻显示横屏还是竖屏的方式
    如果是iOS6之前,下面设置的设备支持方向可在应用里面再被修改
    如果是iOS6以后,会做为硬性条件,也就是如果设置了以后,应用里面的代码也无法再使用这个方向
     
     
    3:传说中的私有API实现切换ViewController强制横屏的方式
    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {  
            [[UIDevice currentDevice] performSelector:@selector(setOrientation:)  
                                           withObject:(id)UIInterfaceOrientationLandscapeRight];  
        }  
     
    4:使用xib进行界面设计时,改变xib的横竖显示方式
  • 相关阅读:
    PageObject小结
    python函数默认参数坑
    编译Android 8.0系统 并刷入pixel
    CF 289 F. Progress Monitoring DP计数
    EDU 61 F. Clear the String 区间dp
    Educational Codeforces Round 55 G 最小割
    Educational Codeforces Round 55 E 分治
    hdu 6430 bitset暴力
    AC自动机+DP codeforces86C
    CF895C dp/线性基
  • 原文地址:https://www.cnblogs.com/yuanjianguo2012/p/3920663.html
Copyright © 2011-2022 走看看