James
James

Reputation: 4052

UIView resizing issue, different results on iPhone/iPad using iOS simulator

I'm making a really simple game for iphone/ipad. On the storyboard the game has a single View, I've added a UIView filling the whole view and called it gameView. I place objects on gameView programmatically at startup.

I resize the gameView in viewDidLoad so that it will work for iPhone 3.5", 4", and iPad. This works fine on both sizes of iPhone, but I get weird error on iPad (I'm using an iPad simulator as I don't own an iPad).

On iPhone there is a green block that sits at the bottom of the screen, but on iPad the green block that should be at the bottom is about a quarter of the way up the screen!

The code I use to resize the view is:

[self.gameView setFrame:self.view.frame];

Is there something I'm doing wrong with the code, or could this be an iOS simulator problem?

Upvotes: 1

Views: 288

Answers (1)

DrummerB
DrummerB

Reputation: 40211

To make a subview fill its superview you have to use the superview's bounds.

self.gameView.frame = self.view.bounds;

If you don't know the difference, read this:
Cocoa: What's the difference between the frame and the bounds?

Upvotes: 1

Related Questions