【发布时间】:2017-08-06 20:23:02
【问题描述】:
我正在制作一款适用于所有 Apple 平台的通用游戏。问题是有很多纵横比,并且随着设备数量的增加,这变得很麻烦。我尝试了以下方法:
var deviceAspectRatio: CGFloat? {
#if os(iOS)
if UIDevice.current.model.contains("iPhone") {
return 16/9
} else if UIDevice.current.model.contains("iPad") {
return 4/3
}
#elseif os(tvOS)
return 16/9 //There might be other aspect ratios also
#elseif os(watchOS)
return 1
#elseif os(macOS)
//figure out aspect ratio
#else
return nil
#endif
}
但即使这样,Xcode 还是给我一个错误:
预期返回“CGFloat”的函数中缺少返回值?
【问题讨论】:
标签: ios xcode macos tvos watchos