可能重复:
检测iPad/iPhone硬件的最佳编程方式
我正在准备一个应用程序,希望在iPhone和iPad上使用。
如何检测当前主机设备是iPhone还是iPad?
根据这一点,我想对用户界面进行更改。
可能重复:
检测iPad/iPhone硬件的最佳编程方式
我正在准备一个应用程序,希望在iPhone和iPad上使用。
如何检测当前主机设备是iPhone还是iPad?
根据这一点,我想对用户界面进行更改。
有很多方法可以查找应用正在运行的设备。
[[[UIDevice currentDevice] systemVersion] floatValue];
通过使用这段代码,我们可以获取当前设备的版本,从而可以检查设备是否为 iPhone 或 iPad。
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// iPad-specific interface here
}
else
{
// iPhone and iPod touch interface here
}
这是在运行时检测设备类型的“官方”方法:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// The device is an iPad running iPhone 3.2 or later.
}
else
{
// The device is an iPhone or iPod touch.
}