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?

Answers


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?


Need Your Help

New Data Structure

c++ data-structures

Recently I felt that along with the basic data structures like stack and queue, a new data structure should be there which stores only the last n values given to it.

406 error when responding with json

ruby-on-rails ruby-on-rails-3 json batman.js

I'm trying to get a rails app running with the node.js framework batman.js via the batman-rails gem.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.