这可能是一个简单的问题,但由于我是初学者,最好问一下。
正如标题所说,我应该使用什么来代替UIScreen.mainScreen().applicationFrame
因为它在 9.0 中已被弃用。
如果可能的话,如果你能给我提供一个样本或例子,那就太好了,因为我发现苹果的文档很难。
目前我使用下面的代码,但我希望将其更改为新版本。我很想听听你的消息!
let sizeRect = UIScreen.mainScreen().applicationFrame
let posX = arc4random_uniform(UInt32(sizeRect.size.width))
let posY = arc4random_uniform(UInt32(sizeRect.size.height))
Enemy.position = CGPoint(x: CGFloat(posX), y: CGFloat(posY))
Use
let rect1 = UIScreen.mainScreen().bounds // Returns CGRect
let rect2 = UIScreen.mainScreen().bounds.size // Returns CGSize
斯威夫特 3+:
let rect1 = UIScreen.main.bounds // Returns CGRect
let rect2 = UIScreen.main.bounds.size // Returns CGSize
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)