问题描述
我想知道是否有人可以告诉我如何编写此代码,以便它针对不同的屏幕大小自动调整大小.我有 4 个不同屏幕尺寸的故事板,只是想要一种显示代码的方法,如果这个故事板那么(数字改变)遵循这个代码,否则(数字根据故事板大小摩擦)这个代码.
I am wondering if someone can show me how to write this code so it resizes automatically for different screen sizes. I have 4 storyboards with different screen sizes and just want a way to show the code, if this storyboard then (numbers change) follow this code, else (numbers chafe according to storyboard size) this code.
我已经尝试通过在每个 y 轴和高度轴之后添加例如/568 * size.frame.height 来调整大小,当然 x 和宽度也是如此,但是代码变得太长且难以阅读.
I already tried resizing by adding to each axis number for example / 568 * size.frame.height after each y and height axis and same for x and width of course, but the code becomes too long and complex to read.
理想情况下,我想要一个 if 语句,说明如果这个屏幕大小,那么它就是故事板这个",然后转到这个代码..
Ideally I'd like an if statement saying if this screen size then it's storyboard 'this' then go to this code..
pianoButtonsWaterDropFrames = [
cNote: (CGRect(x: 33 , y: 40 , width: 20, height: 35), CGRect(x: 33, y: 360, width: 20, height: 35)),
dNote: (CGRect(x: 66 , y: 42 , width: 20, height: 35), CGRect(x: 66, y: 360, width: 20, height: 35)),
eNote: (CGRect(x: 99 , y: 41 , width: 20, height: 35), CGRect(x: 99 , y: 360, width: 20, height: 35)),
fNote: (CGRect(x: 132, y: 48, width: 20, height: 35), CGRect(x: 132, y: 360, width: 20, height: 35)),
gNote: (CGRect(x: 165, y: 39, width: 20, height: 35), CGRect(x: 165, y: 360, width: 20, height: 35)),
aNote: (CGRect(x: 198, y: 57, width: 20, height: 35), CGRect(x: 198, y: 360, width: 20, height: 35)),
bNote: (CGRect(x: 231, y: 60, width: 20, height: 35), CGRect(x: 231, y: 360, width: 20, height: 35)),
cFourNote: (CGRect(x: 263, y: 54, width: 20, height: 35), CGRect(x: 263, y: 360, width: 20, height: 35))
]
任何帮助将不胜感激!
推荐答案
您可以使用 在这个问题中有答案 来检查您的应用程序在哪个 iPhone 上运行.然后就可以使用 switch 语句并调用不同的方法:
You can use HAS answer in this question to check, which iPhone your app is running on. Then you can use a switch statement and call different methods:
let modelName = UIDevice.currentDevice().modelName
switch modelName{
case "iPhone 3G", "iPhone 3GS":
method1()
case "iPhone 4", "iPhone 4S":
method2()
default:
println("no size found")
}
这篇关于快速调整每个故事板问题的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!