我正在更新一个应用程序,需要知道该应用程序是否在iPad上使用。
我查看了网上的代码,找到了下面的代码。我在Xcode中使用了iPad模拟器并运行了这两个if语句。但是每当我运行代码时,什么都没有发生(打印信息没有打印出来)。这个代码能够在模拟器上工作吗?还是我做错了什么?
当我检查它是否为UIUserInterfaceIdiom.phone时,打印语句就执行了,但我在模拟器上使用的是iPad。
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad){
print("This is an iPad")
redoButton.layer.position.y -= 500
}
if UIDevice.current.userInterfaceIdiom == .pad{
print("iPad True")
}
谢谢您
if (UIDevice.current.userInterfaceIdiom == .pad)
。 - Senura Dissanayake