`
啸笑天
  • 浏览: 3434573 次
  • 性别: Icon_minigender_1
  • 来自: China
社区版块
存档分类
最新评论

ios8中的UIScreen

    博客分类:
  • ios
 
阅读更多

 

   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中得到原来的效果可以:

+ (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的值的不同来用       

 

UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.None)

 

  override func prefersStatusBarHidden() -> Bool {
        return false
 
    }

显示横屏statusbar

 

 

 

 

 

 

分享到:
评论

相关推荐

    ios-酷炫重力感应imageView.zip

    重力感应imageView/A grivity ImageView 可以重力感应控制imageView左右滑动的控件,使用方法简单四步: YGGravityImageView *imageView = [[YGGravityImageView ...Xcode 7.3.1编译通过,iOS 9.x、8.x测试通过

    ios - A-常用宏定义

    #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height) //-------------------获取设备大小----判断5--------------------- #define...

    ios-IOS下拉菜单.zip

    menuFrame:CGRectMake([UIScreen mainScreen].bounds.size.width-125- 10, 136, 125, 115) clickIndexHandle:^(NSInteger index) { switch (index) { case 0://这个是选中哪一行的时候的输出,或者执行的动作,...

    iOS 开发中总结的各种工具类。

    iOS 工具类,NSString,UIImage等。###目前包括以下几类 * UIImage * UIScreen * UIView * NSString

    ios-两行代码快速创建一个iOS主流UI框架.zip

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; MainController *mainVc = [[MainController alloc]init]; // 设置根控制器 self.window.rootViewController = mainVc; ...

    ios-无限轮播(自定义PageControl,可定制).zip

    对于加载网络图片时,Demo中使用了YYWebImage,也可自行替换成SDWebImage。 3.重写了和系统UIPageControl一样的功能,可用图片代替PageControl上的点点,也可自定义其颜色以及切换动画。 使用方法:使用方法比较...

    IOS入门之HelloWorld源代码

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; UILabel *label...

    ios-广告图轮播.zip

    ImageScrollView *imgScrollView = [[ImageScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200)]; [self.view addSubview:imgScrollView]; //添加数据 ...

    ios-新特性引导页.zip

    window = UIWindow(frame: UIScreen.main.bounds) if !UserDefaults.standard.bool(forKey: "alreadyUsedApp"){ // 未使用过App,首次使用 let images:[UIImage] = [UIImage(named:"1")!,UIImage(named:...

    ios-字体大小适配-runtime.zip

    runtime字体大小适配 (void)load{ //获取替换后的类方法 Method newMethod = class_... newFont = [UIFont adjustFont:fontSize * [UIScreen mainScreen].bounds.size.width/YourUIScreen]; return newFont; }

    ios开发记录

    UIScreen *screen = [UIScreen mainScreen]; //获得屏幕的大小 CGRect rect = screen.bounds; //判断btn这个指针指向的是UIButton的对象的时候才清空 if([btn isKindOfClass:[UIButton class]]){ [btn ...

    iOS自定义UIButton点击动画特效

    借鉴相关资料,整理了一个很有意思的button动画效果,iOS自定义UIButton点击动画特效 先看一下效果图: 下面贴上代码: ViewController: #import @interface ViewController : UIViewController @end #import ...

    轮播3d旋转

    focusView3.frame = CGRectMake(20, 20, [UIScreen mainScreen].bounds.size.width-40, [UIScreen mainScreen].bounds.size.height-40); [self.view addSubview:focusView3]; focusView3.delegate =self; ...

    iOS保存App中的照片到系统相册或自建相册的方法

    保存照片到系统相册 保存照片到系统相册这个功能很多社交...#define SCREEN [UIScreen mainScreen].bounds.size self.image = [UIImage imageNamed:@”iOSDevTip”]; UIImageView *imageView = [[UIImageView alloc] in

    ios-广告图片滚动器.zip

    ImageScrollView *imgScrollView = [[ImageScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200)]; [self.view addSubview:imgScrollView]; //添加数据 ...

    iOS中常用的宏定义总结

    宏定义在C系开发中可以说占有举足轻重的作用,为了简化开发流程,提升工作效率,收集了一些平时常用的宏定义,今后会不定期更新 1.UI元素 //NavBar高度 #define NAVIGATIONBAR_HEIGHT 44 //StatusBar高度 #define ...

    IOS自定义UIButton九宫格效果

    此篇文章给大家描写如何写自定义九宫格,因为在开发中,这种需求也是常见不少。因此,主要利用UIButton阐述的; 实列不复杂,就两三个步骤完成: 一、定义宽度与高度(self.view) #define SCREEN_WIDTH [UIScreen ...

    IOS之UIWebView的使用(基本知识)

    那么提到了 APP的混合模式开发,在Android开发中有WebView作为混合模式开发的桥梁,当然在IOS中也同样有一个 UIWebView 组件来作为混合模式开发的桥梁,那么下面就对UIWebView的一些基本知识详解一下。 一、...

    iOS像素对齐概念解析

    在iOS中,有一个概念叫做像素对齐,如果像素不对齐,那么在GPU渲染时,需要进行插值计算,这个插值计算的过程会有性能损耗。  在模拟器上,有一个选项可以把像素不对齐的部分显示出来。 逻辑像素与物理像素 在iOS...

Global site tag (gtag.js) - Google Analytics