HKDeviceUtilities
HK Utilities for UIDevice
SUMMARY
此模块提供返回关于 UIDevice 的信息的方法。这是许多其他 Swift HK 模块所必需的模块。
可用的公共实用方法
注意:建议在应对 UIDevice.orientationDidChangeNotification 通知时,稍作延迟调用这些方法,以便宽度和高度有机会更新。
示例
DispatchQueue.main.asyncAfter(deadline: .now() + 0.35) {
let screenWidth = hkScreenWidth()
let screenHeight = hkScreenHeight()
// other code
}
public func hkIsLandscape() -> Bool
使用 UIDevice.current.orientation
:对于 .portrait
、.portraitUpsideDown
:返回 false。对于 .landscapeLeft
、.landscapeRight
:返回 true。任何其他状态:测试 UIScreen.main.bounds.height
与 UIScreen.main.bounds.weight
的匹配情况。
public func hkIsPortrait() -> Bool
使用 UIDevice.current.orientation
:对于 .portrait
、.portraitUpsideDown
:返回 true 对于 .landscapeLeft
、.landscapeRight
:返回 false 其他状态:测试 UIScreen.main.bounds.height
与 UIScreen.main.bounds.width
的大小
public func hkScreenHeight() -> CGFloat
返回 UIScreen.main.bounds.height
public func hkScreenWidth() -> CGFloat
返回 UIScreen.main.bounds.width
public func hkScreenLongerEdge() -> CGFloat
返回 UIScreen.main.bounds.width
和 UIScreen.main.bounds.height
中的较大值
public func hkScreenShorterEdge() -> CGFloat
返回 UIScreen.main.bounds.width
和 UIScreen.main.bounds.height
中的较小值
public func hkScreenSize() -> CGSize
返回由 UIScreen.main.bounds.width
和 UIScreen.main.bounds.height
组成的 CGSize
安装
这将会自动包含在其他HK模块或CocoaPods中。
在您自己的项目中使用
只需将HKDeviceUtilities.swift文件包含到您的项目中或使用CocoaPod。如果您使用的是CocoaPod,请不要忘记导入此模块。
import HKDeviceUtilities