UIDevice(设备) 官方文档翻译 by kino

主题

当前设备的表示形式。

概述

使用UIDevice对象来获取关于设备的信息,比如分配的名称、设备模型、操作系统名称和版本。你还可以使用UIDevice实例来检测设备特征的变化,比如物理方向。你可以使用orientation属性获得当前的朝向,或者通过注册UIDeviceOrientationDidChangeNotification通知来接收变更通知。在使用这两种技术来获取定向数据之前,你必须使用beginGeneratingDeviceOrientationNotifications方法来启用数据传递。当你不再需要跟踪设备方向,调用endGeneratingDeviceOrientationNotifications方法来禁用通知的传递。
类似地,你可以使用UIDevice实例来获取关于电池充电状态(由batteryState属性描述)和充电水平(由batteryLevel属性描述)变化的信息和通知。UIDevice实例还提供了接近传感器状态(由proximityState属性描述)的访问。近距离传感器会检测用户是否将设备贴近自己的脸。只有在需要时才启用电池监测或接近感测。

UIDevice属性列表,属性需要获取currentDevice访问

@property(class, nonatomic, readonly) UIDevice *currentDevice;//返回一个表示当前设备的对象。
@property(nonatomic, readonly, getter=isMultitaskingSupported) BOOL multitaskingSupported;//一个布尔值,指示当前设备上是否支持多任务处理。
@property(nonatomic, readonly, strong) NSString *name;//标识设备的名称
@property(nonatomic, readonly, strong) NSString *systemName;//接收方表示的设备上运行的操作系统的名称。
@property(nonatomic, readonly, strong) NSString *systemVersion;//操作系统的当前版本。
@property(nonatomic, readonly, strong) NSString *model;//模型字符串可能的例子是@ " iPhone "和@ " iPod touch "。
@property(nonatomic, readonly, strong) NSString *localizedModel;//作为本地化字符串的设备模型。
@property(nonatomic, readonly) UIUserInterfaceIdiom userInterfaceIdiom;//在当前设备上使用的接口样式。//对于通用应用程序,可以使用此属性为特定类型的设备定制应用程序的行为。例如,iPhone和iPad设备有不同的屏幕大小,因此您可能希望根据当前设备的类型创建不同的视图和控件。
@property(nullable, nonatomic, readonly, strong) NSUUID *identifierForVendor;//一个由字母和数字组成的字符串,唯一地为应用程序的供应商标识设备。
@property(nonatomic, readonly) UIDeviceOrientation orientation;//返回设备的物理方向。//属性的值是一个常量,它指示设备的当前方向。这个值代表设备的物理方向,可能与你的应用程序的用户界面的当前方向不同。关于可能值的描述,请参阅下面总结的UIDeviceOrientation。
该属性的值总是返回0,除非通过调用beginGeneratingDeviceOrientationNotifications来启用定向通知。
@property(nonatomic, readonly, getter=isGeneratingDeviceOrientationNotifications) BOOL generatesDeviceOrientationNotifications;//一个布尔值,指示接收方是否生成方向通知(YES)。

枚举UIDeviceOrientation

UIDeviceOrientationUnknown//无法确定设备的方向。
UIDeviceOrientationPortrait//设备处于竖屏模式,垂直手持设备,home键在底部。
UIDeviceOrientationPortraitUpsideDown//设备处于竖屏模式,但却是倒置的,设备被垂直手持,home键在顶部。
UIDeviceOrientationLandscapeLeft//设备处于横屏模式,垂直手持设备,home键在右侧。
UIDeviceOrientationLandscapeRight//设备处于横屏模式,垂直手持设备,home键在左侧。
UIDeviceOrientationFaceUp//设备与地面平行,屏幕朝上。
UIDeviceOrientationFaceDown//手持设备与地面平行,屏幕朝下。

判断设备方向的函数

BOOL UIDeviceOrientationIsFlat(UIDeviceOrientation orientation);//返回一个布尔值,该值指示指定的方向是朝上还是朝下。
BOOL UIDeviceOrientationIsLandscape(UIDeviceOrientation orientation);//返回一个布尔值,该值指示设备是否处于横向。
BOOL UIDeviceOrientationIsPortrait(UIDeviceOrientation orientation);//返回一个布尔值,该值指示设备是否处于纵向方向。
BOOL UIDeviceOrientationIsValidInterfaceOrientation(UIDeviceOrientation orientation);//返回一个布尔值,指示指定的方向是纵向方向还是横向方向之一。

方法

beginGeneratingDeviceOrientationNotifications//开始生成设备方向改变的通知。
endGeneratingDeviceOrientationNotifications//结束设备方向变化通知的生成。

判断设备的电池状态

@property(nonatomic, readonly) float batteryLevel;//设备的电池充电水平。电池电量范围从0.0(完全放电)到1.0(100%充电)。在访问此属性之前,请确保电池监控已启用。
如果未启用电池检测,电池状态为UIDeviceBatteryStateUnknown,该属性的值为-1.0。
@property(nonatomic, getter=isBatteryMonitoringEnabled) BOOL batteryMonitoringEnabled;//一个布尔值,指示是否启用电池检测(YES)或否(NO)。
@property(nonatomic, readonly) UIDeviceBatteryState batteryState;//设备的电池状态。
@property(nonatomic, readonly) BOOL proximityState;//一个布尔值,指示接近传感器是否接近用户(YES) (NO)。

UIDeviceBatteryState 枚举

UIDeviceBatteryStateUnknown//无法确定设备的电池状态。
UIDeviceBatteryStateUnplugged//设备未插电源;电池正在放电。
UIDeviceBatteryStateCharging//设备已插入电源,电池电量不足100%。
UIDeviceBatteryStateFull//设备插入电源,电池100%充满电。

自定义键盘支持点击声音的效果

- (void)playInputClick;//在启用的输入视图中单击。使用此方法播放标准系统键盘点击以响应用户在自定义输入或键盘附件视图中点击。只有当用户在“设置>声音”中启用了键盘点击,并且输入视图本身是启用和可见的时候,点击才会播放。
要为输入点击启用自定义输入视图或附件视图,请执行以下两个步骤:
在你的输入视图类中采用UIInputViewAudioFeedback协议。
实现enableInputClicksWhenVisible委托方法以返回YES。

UIUserInterfaceIdiom//具有特征环境的设备或对象的接口类型,例如视图和视图控制器。

经常用来判断是否为iphone,ipad

typedef enum UIUserInterfaceIdiom : NSInteger {
    UIUserInterfaceIdiomUnspecified = -1
UIUserInterfaceIdiomPhone//为iPhone和iPod touch设计的界面。
UIUserInterfaceIdiomPad//为iPad设计的界面。
UIUserInterfaceIdiomTV//An interface designed for tvOS and Apple TV.
UIUserInterfaceIdiomCarPlay//一个为车内体验而设计的界面。
UIUserInterfaceIdiomMac = 5//为Mac设计的接口。
} UIUserInterfaceIdiom;

函数UI_USER_INTERFACE_IDIOM//返回当前设备支持的接口风格(推荐运行在3.2之前iOS版本中的应用)。

通知:

UIDeviceBatteryLevelDidChangeNotification//电池电量变化时发送
UIDeviceBatteryStateDidChangeNotification//当电池状态改变时发送
UIDeviceOrientationDidChangeNotification//当设备的方向改变时发送
UIDeviceProximityStateDidChangeNotification//当接近传感器的状态改变时发送

你可能感兴趣的:(UIDevice(设备) 官方文档翻译 by kino)