I’ve never played around with the iPhone being landscape, but I have a fully working iPhone app that is all assuming the user is viewing the iPhone upright. I’d like to play around with rotating the phone, and in order to do that, I did something very simple:
I added the following code to my View Controller:
-(void)willRotateToInterfaceOrientation: (UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {
NSLog(@"WILL ROTATE TO INTERFACE ORIENTATION: %@",orientation);
if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight))
tableView.frame = CGRectMake(0, 0, 480, 320);
else
tableView.frame = CGRectMake(0,73,320,390);
}
and I’m getting a BAD_ACCESS error. I don’t see the view load at all. So, what’s the problem, and how do I properly implement the willRotate method so that when the phone rotates, I can resize all my components?
The crash is caused by this line:
orientationis anenumvalue, therefore the format specifier should be%inot%@.The simplest way to support rotating is to implement:
Return
YESfor the orientations you wish to support. Do not doing any resizing in this method. Use the views struts and springs to ensure that they resize and reposition themselves correctly for the alternate rotations.