UIScreen简介

来源:互联网 发布:程序员简历范文 编辑:程序博客网 时间:2024/06/06 05:01

UIScreen对象定义了一种基于硬件的显示相关的属性,UIScreen对象可以充当iOS设备物理屏幕的替代者(相当于屏幕)。使用这个类来获得每个显示器设备的屏幕对象。每个屏幕对象中包含了一些屏幕相关的属性。


获取可用的屏幕对象:


1.返回一个包含所有连接到设备的屏幕的数组

+ (NSArray *)screens NS_AVAILABLE_IOS(3_2);

返回的数组包含主屏幕加上任何其他连接到设备的屏幕。主屏幕在返回的数组中总是在索引0并非所有设备都支持外部(连接)显示器(如iphone连接到apple TV这样的)。目前,外部连接显示器支持iPhone和ipad iPod-touch等。旧设备,如iPhone 3GS不支持外部显示器。连接外部显示器要求装置和显示之间适当的电缆


2.返回当前设备的屏幕对象:

+ (UIScreen *)mainScreen; 


3.外部镜像屏幕(只读):

@property(nonatomic,readonly,retain) UIScreen *mirroredScreen NS_AVAILABLE_IOS(4_3);


获取屏幕信息范围:


4.屏幕分辨率:

@property(nonatomic,readonly) CGFloat scale NS_AVAILABLE_IOS(4_0);

例如:

float scale = [[UIScreen mainScreen] scale];

标准屏幕(iPhone 4以前)值是1,视网膜屏幕的值是2。在系统scale=2.0时,加载图像时先找@2x的。


5.屏幕大小:

@property(nonatomic,readonly) CGRect  bounds;
例如:

CGRect rectScreen = [[UIScreen mainScreen] bounds];NSLog(@"手机画面大小->%@",NSStringFromCGRect(rectScreen));


6.app应用画面大小:

@property(nonatomic,readonly) CGRect  applicationFrame; 

例如:

CGRect rect = [[UIScreen mainScreen] applicationFrame];NSLog(@"app画面大小->%@",NSStringFromCGRect(rect));


7.物理屏幕分辨率:

@property(nonatomic,readonly) CGFloat nativeScale  NS_AVAILABLE_IOS(8_0);


8.物理屏幕边框像素:

@property(nonatomic,readonly) CGRect  nativeBounds NS_AVAILABLE_IOS(8_0); 


获取屏幕坐标空间:

9.屏幕当前的坐标空间:

@property (readonly) id <UICoordinateSpace> coordinateSpace NS_AVAILABLE_IOS(8_0);


10.屏幕的坐标空间:

@property (readonly) id <UICoordinateSpace> fixedCoordinateSpace NS_AVAILABLE_IOS(8_0);


访问屏幕的模式:

11.屏幕的首选显示模式:

@property(nonatomic,readonly,retain) UIScreenMode *preferredMode NS_AVAILABLE_IOS(4_3); 


12.这个屏幕所支持的模式列表:

@property(nonatomic,readonly,copy) NSArray *availableModes NS_AVAILABLE_IOS(3_2);


13.当前这个屏幕的模式:

@property(nonatomic,retain) UIScreenMode *currentMode NS_AVAILABLE_IOS(3_2);   


要显示的连接:

14.返回屏幕当前连接对象:

- (CADisplayLink *)displayLinkWithTarget:(id)target selector:(SEL)sel NS_AVAILABLE_IOS(4_0);


设置显示亮度:

15.设置屏幕当前的亮度水平:

@property(nonatomic) CGFloat brightness

此属性仅在主屏幕获得支持。此属性的值应该是0和1之间的数。亮度变化对应用程序仍然有效,但只有当应用程序是活动的。当你的应用程序不在前台时,系统恢复亮度设置。


16.使用软件来模拟更低的亮度:

@property(nonatomic) BOOL wantsSoftwareDimming NS_AVAILABLE_IOS(5_0); 

默认是NO。如果YES,可以通过wantsSoftwareDimming属性来声明此应用需要将屏幕亮度调整到比中等亮度偏暗的级别。(需要注意的是,打开wantsSoftwareDimming可能会对性能有影响,因为这种昏暗是通过软件来实现的。)  


设置显示的扫描补偿:

17.调整外接显示器的过扫描补偿:

@property(nonatomic) UIScreenOverscanCompensation overscanCompensation NS_AVAILABLE_IOS(5_0); 

过扫描指的是一种起源与阴极射线管显示器的行为。由于技术上的限制,旧的CRT扫描输入的图片时可能会越过显示管的边界,造成显示的图像不完整。虽然这个技术限制应该解决,许多广播和显示器厂家仍然期望过扫描。使用overscanCompensation属性的默认值,也就是UIScreenOverscanCompensationScale,当iOS检测到外接显示器存在过扫描时,它会适当的缩放你的内容。在极少数情况下,你需要使用其他值来设置overscanCompensation属性,这样做总会导致你不得不做更多的工作。

捕获屏幕快照:

返回一个基于当前屏幕内容的快照视图:

- (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates NS_AVAILABLE_IOS(7_0);

在iOS7 以前, 获取一个UIView的快照有以下步骤: 首先创建一个UIGraphics的图像上下文,然后将视图的layer渲染到该上下文中,从而取得一个图像,最后关闭图像上下文,并将图像显示在UIImageView中。现在我们只需要一行代码就可以完成上述步骤了:

[view snapshotViewAfterScreenUpdates:NO]; 
这个方法制作了一个UIView的副本,如果我们希望视图在执行动画之前保存现在的外观,以备之后使用(动画中视图可能会被子视图遮盖或者发生其他一些变化),该方法就特别方便。
afterUpdates参数表示是否在所有效果应用在视图上了以后再获取快照。例如,如果该参数为NO,则立马获取该视图现在状态的快照。


常数:

18.补偿扫描相关常数:

// when the connected screen is overscanning, UIScreen can attempt to compensate for the overscan to avoid clippingtypedef NS_ENUM(NSInteger, UIScreenOverscanCompensation) {    UIScreenOverscanCompensationScale,                 // the final composited framebuffer for the screen is scaled to avoid clipping    UIScreenOverscanCompensationInsetBounds,           // the screen's bounds will be inset in the framebuffer to avoid clipping. no scaling will occur    UIScreenOverscanCompensationInsetApplicationFrame, // the screen's applicationFrame will be inset in the bounds. content drawn in the bounds outside applicationFrame may be clipped};<span style="font-family:Menlo;color:#008400;"><span style="font-size: 11px;"></span></span>


通知:

19.通知:

// Object is the UIScreen that represents the new screen. Connection notifications are not sent for screens present when the application is first launchedUIKIT_EXTERN NSString *const UIScreenDidConnectNotification NS_AVAILABLE_IOS(3_2);// Object is the UIScreen that represented the disconnected screen.UIKIT_EXTERN NSString *const UIScreenDidDisconnectNotification NS_AVAILABLE_IOS(3_2);// Object is the UIScreen which changed. [object currentMode] is the new UIScreenMode.UIKIT_EXTERN NSString *const UIScreenModeDidChangeNotification NS_AVAILABLE_IOS(3_2);UIKIT_EXTERN NSString *const UIScreenBrightnessDidChangeNotification NS_AVAILABLE_IOS(5_0);



0 0