获取主屏幕对象
UIScreen *screen =[UIScreen mainScreen];
截屏
利用的当前在Screen上的部分生成一个UIView,利用这个UIVIew可以做一些全屏的动画。注意,这样的效果是比生成一副图片的效率要高的。
- (UIView * nonnull)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates
效果如下:

坐标系
coordinateSpace
这个函数返回遵循UICoordinateSpace协议的对象,这个协议封装了坐标系的信息以及坐标系转换的函数。UIView和UIScreen的对象都实现了这个协议。
UIScreen * screen = [UIScreen mainScreen];
id<UICoordinateSpace> coor = [screen coordinateSpace];
把UIView的一个点进行坐标系转换到固定的UIScreen坐标系
[customView convertPoint:CGPointMake(30, 30) toCoordinateSpace:customView.window.screen.fixedCoordinateSpace];
fixedCoordinateSpace
和上文CoordinateSpace唯一不同的是,这个返回的是 portrait-up的坐标系,也就是说是不变的。而CoordinateSpace会随着设备下旋转而改变。
Bounds/NativeBounds
·bounds 以点为单位,随着屏幕方向变化而变化
·NativeBounds 以像素为单位,固定为portrait-up的坐标系
例如:
监听屏幕旋转并且log
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
UIScreen * screen = [UIScreen mainScreen];
[self LogFrame:[screen bounds]];
[self LogFrame:[screen nativeBounds]];
}
竖直方向
1.打印:0.000000 0.000000 320.000000 480.000000
2.打印: 0.000000 0.000000 640.000000 960.000000
横屏方向:
1.打印: 0.000000 0.000000 480.000000 320.000000
2.打印: 0.000000 0.000000 640.000000 960.000000
NativeScale/Scale
从一个point到像素点的转换关系。例如:在普通屏幕上,1个点对应一个像素,5s和6等视网膜显示屏1个点对应4个像素。在6p上,一个点对应9个像素。
亮度
通过修改属性brightness
来修改亮度。
[UIScreen mainScreen].brightness =0.9;
Screen Mode有三个属性
preferredMode 偏好的显示模式
availableModes 支持的显示模式
currentMode 当前的显示模式
返回对象是UIScreenMode
,包含了size 屏幕的大小(以像素为单位)和pixelAspectRatio
(像素的横纵比)
UIScreen * screen = [UIScreen mainScreen];
UIScreenMode *perferedMode = screen.preferredMode;
NSLog(@"Width:%f Height:%f AspectRatio:%f",perferedMode.size.width,perferedMode.size.height,perferedMode.pixelAspectRatio);
结果为:
Width:640.000000 Height:1136.000000 AspectRatio:1.000000
网友评论