[英]iPhone simulator (detect different device simulators)
With the upcoming release of the iPhone X, I want to be able to display a different UI layout for the iPhone X (due to round corners and bottom line, which kinda works as the home button replacement).随着即将发布的 iPhone X,我希望能够为 iPhone X 显示不同的 UI 布局(由于圆角和底线,这有点像主页按钮的替代品)。
I am using the following nuget package to retrieve the model information: https://github.com/dannycabrera/Get-iOS-Model我正在使用以下 nuget 包来检索模型信息: https : //github.com/dannycabrera/Get-iOS-Model
It works perfectly fine, but all the different simulators (iPhone 7, 8, X) only come up as Simulator.它工作得很好,但所有不同的模拟器(iPhone 7、8、X)都只作为模拟器出现。
Is there a way to differentiate between the different iPhone Simulators in code within my Xamarin mobile app?有没有办法在我的 Xamarin 移动应用程序中的代码中区分不同的 iPhone 模拟器?
Many thanks, Nik非常感谢,尼克
Since the simulator is a weird animal, the screen size is as good as any other test after the other tests for iOS version and the availability of FaceID on a physical device:由于模拟器是一个奇怪的动物,在对 iOS 版本和 FaceID 在物理设备上的可用性进行其他测试之后,屏幕尺寸与任何其他测试一样好:
public bool iPhoneX()
{
var version = new Version(ObjCRuntime.Constants.Version);
if (version < new Version(11, 0))
return false;
if (ObjCRuntime.Runtime.Arch == ObjCRuntime.Arch.DEVICE)
{
using (var context = new LocalAuthentication.LAContext())
{
if (context.BiometryType == LABiometryType.TypeFaceId)
return true;
}
return false;
}
if (UIScreen.MainScreen.PreferredMode.Size.Height == 2436)
return true;
return false;
}
Or an optimized property for repeated (binding) calls:或者重复(绑定)调用的优化属性:
static bool? iPhoneX;
public bool isPhoneX
{
get
{
if (iPhoneX == null)
{
if (new Version(ObjCRuntime.Constants.Version) < new Version(11, 0))
iPhoneX = false;
else
{
if (ObjCRuntime.Runtime.Arch == ObjCRuntime.Arch.DEVICE)
{
using (var context = new LocalAuthentication.LAContext())
{
iPhoneX = context.BiometryType == LABiometryType.TypeFaceId;
}
}
else
iPhoneX = UIScreen.MainScreen.PreferredMode.Size.Height == 2436;
}
}
return (bool)iPhoneX;
}
}
您应该简单地使用安全区域布局指南,它会自动增加 iPhone X 上的顶部/底部边距。
As others have pointed out you should definitely be using the Safe Area Layout Guide .正如其他人指出的那样,您绝对应该使用Safe Area Layout Guide 。
If you really really have a need to detect the model then look for the SIMULATOR_MODEL_IDENTIFIER
environment variable.如果您真的需要检测模型,请查找
SIMULATOR_MODEL_IDENTIFIER
环境变量。 iPhone X will return iPhone10,3
. iPhone X 将返回
iPhone10,3
。
let model = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.