UIScreen详解:定时器,快照,亮度,尺寸等实现方法
2014-12-24 22:36
489 查看
UIScreen对象定义一些与硬件显示相关的属性。iOS设备有主屏幕或0到多个附加屏幕。
iOS8新增加了API定义竖屏和任意屏幕的CoordinateSpace方法,更加灵活。
获得屏幕
屏幕相关
定时器
iOS8新增加了API定义竖屏和任意屏幕的CoordinateSpace方法,更加灵活。
获得屏幕
//获得主屏幕 let mainScreen = UIScreen.mainScreen() //获得主屏幕及其附加的屏幕,一般情况下只有一个屏幕 let screens = UIScreen.screens()坐标空间,iOS8新方法
//坐标空间,bounds随着屏幕方向变化而变化,如果横屏iPhone6为,(0.0, 0.0, 375.0, 667.0) let coordinateSpace = mainScreen.coordinateSpace //坐标空间,bounds始终时竖屏是的尺寸,iPhone6为(0.0,0.0,375.0,667.0) let fixedCoordinateSpace = mainScreen.fixedCoordinateSpace
屏幕相关
//按点来计算,iPhone6为(0.0,0.0,375.0,667.0) let bounds = mainScreen.bounds //按点来算app window的frame,不包括状态条,iPhone6为(0.0,20.0,375.0,647.0) let applicationFrame = mainScreen.applicationFrame //按像素点来计算,物理屏幕的尺寸,iPhone6为(0.0,0.0,750.0,1334.0) let nativeBounds = mainScreen.nativeBounds //物理屏幕的比例因子,视网膜屏幕都是2.0 let nativeScale = mainScreen.nativeScale //点和像素的比例,视网膜为2.0 let scale = mainScreen.scale屏幕模式
let preferredModel = mainScreen.preferredMode.size let preferredModelr = mainScreen.preferredMode.pixelAspectRatio
定时器
//定时器 let displayLink = mainScreen.displayLinkWithTarget(self, selector: Selector("refreshNumber")) //120表示120帧(2秒)重复一次 displayLink.frameInterval = 120 displayLink .addToRunLoop(NSRunLoop.currentRunLoop(), forMode: NSRunLoopCommonModes)屏幕亮度
//调整屏幕的亮度,0-1之间的数字,亮度只在app为active状态有效,background状态会恢复 mainScreen.brightness = 0.5 //设置为YES时,会在屏幕上加一层dimming view,所以设置为0时也会有一定的亮度哦 mainScreen.wantsSoftwareDimming = true屏幕快照
//屏幕快照:参数表示是否立即生产快照,如果立即生产快照则之后的一些变化不会被记录,返回一个UIView,能够对view添加内容,但是不能修改layer.contens。 mainScreen.snapshotViewAfterScreenUpdates(true)UIScreen的相关通知
//有四个通知 UIScreenDidConnectNotification UIScreenDidDisconnectNotification UIScreenModeDidChangeNotification UIScreenBrightnessDidChangeNotification
相关文章推荐
- Android 三种实现定时器详解及实现方法
- quartz实现定时功能实例详解(servlet定时器配置方法)
- 详解Android实现定时器的几种方法
- quartz实现定时功能实例详解(servlet定时器配置方法)
- Android实现定时器的三种方法及详解
- Android实现定时器的五种方法实例详解
- quartz实现定时功能实例详解(servlet定时器配置方法)
- VC++实现非窗口类中使用定时器的方法(图)
- ASP.Net中定时器的一种实现方法
- 详解Oracle用户解锁命令的两则实现方法
- C#创建文件夹实现方法详解
- VC++实现非窗口类中使用定时器的方法
- C#中Bitmap类实现对图像操作的一些方法(Asp.net(C#)-放大缩小图片尺寸)
- 在.Net框架中 C# 实现多线程的同步方法详解
- 详解两种C#自动实现DLL(OCX)控件注册的方法
- VC++实现非窗口类中使用定时器的方法
- JS实现数字转换为货币汉字大写数字的方法详解
- 详解Oracle用户解锁命令的两则实现方法
- NAT详解及CISCO路由器上的实现方法
- C# 实现多线程的同步方法详解