I'm making a Breakout game (for Stanford CS193p) with a grid of bricks. The width of each brick is let width = frame.size.width / CGFloat(bricksPerRow)
and everything works fine, but only when the Interface Builder is set to the same device as the simulator! If they are different, the frame used to calculate the width is always the size of the device I have selected in the IB, not the size of the device running in the simulator.
For example, if I have the Interface Builder showing iPhone 7, but I run the simulator on iPhone SE, the blocks are too big for the screen. I know there's not really a good reason to be using different devices in the IB and on the simulator, but when I first ran the app it was, by accident/chance, under these conditions, and, you know, shouldn't autolayout have the frame be the size of the device?
Here's the code for the dimensions of the bricks, with some printing thrown in for debugging. The printouts confirm that the frame is the same no matter what device I run on. Again, everything is being drawn properly for the frame it uses, it's just using the wrong frame.
var brickSize: CGSize {
print(frame.size)
let width = frame.size.width / CGFloat(bricksPerRow)
let height = width * 2/3
print("Calculated width: \(frame.size.width / CGFloat(bricksPerRow))")
print("'Actual' width: \(width)")
return CGSize(width: width, height: height)
}
This is in the code for my view, in the storyboard the view's constraints appear to be set correctly (trailing and leading both to superview).