zoukankan      html  css  js  c++  java
  • ios8中的UIScreen

    Java代码 复制代码 收藏代码
    1. let orientation: UIInterfaceOrientation = UIApplication.sharedApplication().statusBarOrientation  
    2.      println("Currently landscape: " + ((orientation == UIInterfaceOrientation.LandscapeLeft||orientation == UIInterfaceOrientation.LandscapeRight) ?"YES":"NO"))  
    3.      println("UIScreen.mainScreen().bounds: (UIScreen.mainScreen().bounds)")  
    4.      println("UIScreen.mainScreen().applicationFrame: (UIScreen.mainScreen().applicationFrame)")  
       let orientation: UIInterfaceOrientation = UIApplication.sharedApplication().statusBarOrientation
            println("Currently landscape: " + ((orientation == UIInterfaceOrientation.LandscapeLeft||orientation == UIInterfaceOrientation.LandscapeRight) ?"YES":"NO"))
            println("UIScreen.mainScreen().bounds: (UIScreen.mainScreen().bounds)")
            println("UIScreen.mainScreen().applicationFrame: (UIScreen.mainScreen().applicationFrame)")

     在ios7中输出:

    Currently landscape: NO

    UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)

    UIScreen.mainScreen().applicationFrame: (0.0,20.0,320.0,548.0)

    Currently landscape: YES

    UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)

    UIScreen.mainScreen().applicationFrame: (20.0,0.0,300.0,568.0)

    在ios8中输出:

    Currently landscape: NO

    UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)

    UIScreen.mainScreen().applicationFrame: (0.0,20.0,320.0,548.0)

    Currently landscape: YES

    UIScreen.mainScreen().bounds: (0.0,0.0,568.0,320.0)

    UIScreen.mainScreen().applicationFrame: (0.0,0.0,568.0,320.0)

    结论:

    1、在ios7中UIScreen.mainScreen().bounds是固定不变的值,在ios8中他的值是随横竖屏改变的!

    为了在ios8中得到原来的效果可以:

    Java代码 复制代码 收藏代码
    1. + (CGSize)screenSize {  
    2.     CGSize screenSize = [UIScreen mainScreen].bounds.size;  
    3.     return CGSizeMake(MIN(screenSize.width, screenSize.height), MAX(screenSize.width, screenSize.height));  
    4. }  
    + (CGSize)screenSize {
        CGSize screenSize = [UIScreen mainScreen].bounds.size;
        return CGSizeMake(MIN(screenSize.width, screenSize.height), MAX(screenSize.width, screenSize.height));
    }

    2、

    在ios8中增加了2个属性:

    nativeBounds :  屏幕像素,不随横竖平改变的!

    nativeScale   :1(non retina)/2(retina)/3(retina hd)

    https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIScreen_Class/index.html#//apple_ref/occ/instp/UIScreen/nativeBounds

    ios8输出:

    Currently landscape: YES

    UIScreen.mainScreen().bounds: (0.0,0.0,568.0,320.0)

    UIScreen.mainScreen().applicationFrame: (0.0,20.0,568.0,300.0)

    UIScreen.mainScreen().nativeBounds: (0.0,0.0,640.0,1136.0)

    UIScreen.mainScreen().nativeScale: 2.0

    Currently landscape: NO

    UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)

    UIScreen.mainScreen().applicationFrame: (0.0,20.0,320.0,548.0)

    UIScreen.mainScreen().nativeBounds: (0.0,0.0,640.0,1136.0)

    UIScreen.mainScreen().nativeScale: 2.0

    3、从UIScreen.mainScreen().applicationFrame输出值看出,ios8默认横屏statusbar是隐藏掉了。你可以根据plist中

    View controller-based status bar appearance的值的不同来用       

    Java代码 复制代码 收藏代码
    1. UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.None)  
    UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.None)

    Java代码 复制代码 收藏代码
    1. override func prefersStatusBarHidden() -> Bool {  
    2.       return false  
    3.   
    4.   }  
      override func prefersStatusBarHidden() -> Bool {
            return false
     
        }

    显示横屏statusbar

  • 相关阅读:
    Android环境配置问题
    Android diary 1
    Android diary 2
    myeclipse常见问题
    Mysql常用命令
    桉树系统公司市场高级副总裁David Butler:全球最广泛应用的企业内部云平台
    引用外部.css或.js文件的路径问题
    [基础知识]巧用项目生成事件属性自动打包
    TSQL经验总结
    [Silverlight]UI 开发规范
  • 原文地址:https://www.cnblogs.com/lovewx/p/4224533.html
Copyright © 2011-2022 走看看