这可能是一个简单的问题,但由于我是一个初学者,这是最好的问。
正如标题所述,我应该使用什么来代替UIScreen.mainScreen().applicationFrame,因为它在9.0中被废弃了。
如果可能的话,如果您能给我提供一个示例或示例,那就太好了,因为我觉得Apples文档很难。
目前,我使用下面的代码,但我希望将其更改为新版本。我很想听听你的消息!
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))发布于 2015-10-31 08:54:36
使用
let rect1 = UIScreen.mainScreen().bounds // Returns CGRect
let rect2 = UIScreen.mainScreen().bounds.size // Returns CGSizeSwift 3+ :
let rect1 = UIScreen.main.bounds // Returns CGRect
let rect2 = UIScreen.main.bounds.size // Returns CGSize发布于 2017-05-17 16:15:53
我知道UIScreen.mainScreen().bounds是推荐的替代方案;然而,它并不完全等同于UIScreen.mainScreen().applicationFrame,特别是当您的应用程序没有占据整个屏幕时,这种情况发生在特定iPads上的Split和Slide功能上。
在这种情况下,这是一个很好的选择:UIApplication.sharedApplication.keyWindow.frame。(当然keyWindow必须是可用的,也就是说,您确实调用了makeKeyAndVisible)
发布于 2017-10-16 17:29:42
从斯威夫特3开始,你需要像现在这样使用它。
let SCREEN_WIDTH = UIScreen.main.bounds.size.width
let SCREEN_HEIGHT = UIScreen.main.bounds.size.heighthttps://stackoverflow.com/questions/33449696
复制相似问题