iOS 8 Code working on iPhone 5s but not iPhone 5

自闭症网瘾萝莉.ら 提交于 2019-12-05 19:29:38

The debugger is misleading you. The real problem is arc4random, which will return an UInt32 on both iPhone 5 and 5s. But as iPhone 5 is a 32-bit device, the Int(arc4random()) will cause an overflow if the random number is big enough.

Instead of using Int(arc4random()), you can try to replace it by using arc4random_uniform. Maybe the code below will do the trick for you.

var positionX: CGFloat = CGFloat(arc4random_uniform(500)) + CGFloat(70.0)
var positionY: CGFloat = CGFloat(arc4random_uniform(1007)) + CGFloat(63.0)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!