View overlapped by the title bar
During the development of my latest iPhone project I faced a strange phenomenon: if I enable the title bar on a screen, the current view is placed to the coordinates (0,0), right beneath the title bar. Also, since the height of the view is not 100% (to leave space for the title bar), there’s an empty space left under the view.
Here’s an example:
For me it’s a surprise why isn’t this case handled automatically in the iPhone SDK, but with the following solution we can overcome this problem:
In the ViewController of the view add the following method:
- (void)viewWillAppear:(BOOL)animated
{
self.view.frame = [[UIScreen mainScreen] applicationFrame];
}
Before finding this solution I had to use a hack: in -(void)viewDidLoad I repositioned the view manually to its correct place. This was not only not elegant, but with the release of new iOS devices (with their different screen resolutions) this hack could have meant a potential compatibility problem.
