4

我正在使用自定义键盘,如果我在课堂上包含此代码,则会出现错误:

let isPad = UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad

Error - Command/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

我需要这段代码,因为当用户在 iPad 上运行 iPhone 应用程序(如 instagram)时,我需要加载 iPhone 键盘预设并使用它的几何图形。我尝试了以下代码,但这不是解决方案:

如果 UI_USER_INTERFACE_IDIOM() == .Pad {

}

所以如果有人有任何解决方案,请分享。

错误截图

4

1 回答 1

3

尝试这个:

if UIDevice.currentDevice().userInterfaceIdiom == .Pad {

    // iPad Stuff
}

else if UIDevice.currentDevice().userInterfaceIdiom == .Phone {

    // iPhone Stuff
}

编辑

斯威夫特 3

if UIDevice.current.userInterfaceIdiom == .pad {

    // iPad Stuff
}

else if UIDevice.current.userInterfaceIdiom == .phone {

    // iPhone Stuff
}
于 2015-08-11T06:00:14.687 回答