Reputation: 171
I am following some tutorials online but the code is meant for an iPad. I am working with an iPhone and the screen sizes are different. The problem is that the author uses 'magic numbers' that are made specifically for the iPad.
I have been successful in creating conversions so that it will work for any device. For example:
let xMid : CGFloat = CGRectGetMidX(self.frame)
let yMid : CGFloat = CGRectGetMidY(self.frame)
print("x: \(xMid) y: \(yMid)")
let height : CGFloat = CGRectGetHeight(self.frame)
let width : CGFloat = CGRectGetWidth (self.frame)
makeSlotAt(CGPoint(x: xMid / 4.0, y: 0), isGood: true)
makeSlotAt(CGPoint(x: xMid - xMid / 4.0, y: 0), isGood: false)
makeSlotAt(CGPoint(x: xMid + xMid / 4.0, y: 0), isGood: true)
makeSlotAt(CGPoint(x: xMid * 2.0 - xMid / 4.0, y: 0), isGood: false)
makeBouncerAt(CGPoint(x: 0, y: 0))
makeBouncerAt(CGPoint(x: xMid / 2.0, y: 0))
makeBouncerAt(CGPoint(x: xMid, y: 0))
makeBouncerAt(CGPoint(x: xMid * 1.5, y: 0))
makeBouncerAt(CGPoint(x: xMid * 2.0, y: 0))
Anyway, I was just wondering if there was a function or cheat sheet that had numerical conversions between device sizes.
Thanks!
Upvotes: 0
Views: 292
Reputation: 13893
If the tutorial you're using uses magic numbers, then stop using it immediately. If you use autolayout and follow Apple's guidelines for iOS 7 & up, you rarely, if ever, need to use magic numbers. The functions that you created are a good start for in-code measurements.
Upvotes: 3