有没有办法在Swift中获取设备型号名称(iPhone 4S,iPhone 5,iPhone 5S等)?
我知道有一个名为的属性,UIDevice.currentDevice().model但它只返回设备类型(iPod touch,iPhone,iPad,iPhone模拟器等).
我也知道可以使用这种方法在Objective-C中轻松完成:
#import <sys/utsname.h>
struct utsname systemInfo;
uname(&systemInfo);
NSString* deviceModel = [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
Run Code Online (Sandbox Code Playgroud)
但是我正在Swift中开发我的iPhone应用程序,所以有人可以用同样的方式帮助我在Swift中解决这个问题吗?
在纵向模式下的iPhone X上,如果将安全区域的底部约束设置为0,则最终会在屏幕底部留出额外的空间.你如何以编程方式获得这个额外填充的高度?
我设法手动确定这个填充的高度是34,这是我如何设法用iPhone X检测实现它:
Swift 4.0和Xcode 9.0
if UIDevice().userInterfaceIdiom == .phone
{
switch UIScreen.main.nativeBounds.height
{
case 2436: //iPhone X
self.keyboardInAppOffset.constant = -34.0
default:
self.keyboardInAppOffset.constant = 0
}
}
Run Code Online (Sandbox Code Playgroud)
有没有更清晰的方法来检测这个填充的高度?