Swift UIScreen.mainscreen.bounds返回错误的宽度&;高度

Swift UIScreen.mainscreen.bounds返回错误的宽度&;高度,swift,Swift,我正在使用SpriteKit制作一个Swift游戏,但是我在将一个精灵放在屏幕中央时遇到了一些困难 以下是我获取尺寸的方法: let screenHeight = UIScreen.mainScreen().bounds.height let screenWidth = UIScreen.mainScreen().bounds.width 我也试过: screenWidth = self.frame.width 但两者都返回相同的值768x1024(纵向) 是否有其他方法获取屏幕尺寸,或者我

我正在使用SpriteKit制作一个Swift游戏,但是我在将一个精灵放在屏幕中央时遇到了一些困难

以下是我获取尺寸的方法:

let screenHeight = UIScreen.mainScreen().bounds.height
let screenWidth = UIScreen.mainScreen().bounds.width
我也试过:

screenWidth = self.frame.width
但两者都返回相同的值768x1024(纵向)


是否有其他方法获取屏幕尺寸,或者我做错了什么?

其中有一个额外的
.size

那就是

let screenHeight = UIScreen.mainScreen().bounds.size.height
let screenWidth = UIScreen.mainScreen().bounds.size.width

调用
mainScreen().bounds
将为您提供一个边界,您必须获得该边界才能获取高度和宽度(请特别参阅和)。

感谢您的回复。但是,UIScreen.mainScreen().bounds.size.height返回相同的值,UIScreen.mainScreen().applicationFrame也返回相同的值。width@CalebCheng它返回的值是否不正确?您在寻找什么值?抱歉,该值是正确的(2048x1536/2)。。。。仍然无法使精灵在中心正确定位。谢谢你的帮助。@CalebCheng没问题;很高兴我能帮忙。看起来它可以帮你稍微居中一点,因为他们谈论如何在屏幕上定位和锚定精灵。哈哈,我是个白痴。没有增加精灵的宽度。谢谢你的帮助