For the question asked here I got the solution, but I don't like the code how is written.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
UIInterfaceOrientation appOrientation = [UIApplication sharedApplication].statusBarOrientation;
float width = self.view.bounds.size.width;
float height = self.view.bounds.size.height;
//NSLog(@"width %3.0f, height: %3.0f", width, height);
// UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,
// UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
// UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,
// UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft
CGFloat angle = 0;
// rotate from Portait
if((fromInterfaceOrientation == UIInterfaceOrientationPortrait) && (appOrientation == UIInterfaceOrientationLandscapeLeft)){
angle = -(M_PI / 2.0);
}
else if((fromInterfaceOrientation == UIInterfaceOrientationPortrait) && (appOrientation == UIInterfaceOrientationLandscapeRight)){
angle = (M_PI / 2.0);
}
// rotate from PortraitUpsideDown
else if((fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) && (appOrientation == UIInterfaceOrientationLandscapeLeft)){
angle = (M_PI / 2.0);
}
else if((fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) && (appOrientation == UIInterfaceOrientationLandscapeRight)){
angle = -(M_PI / 2.0);
}
//rotate from Landscape:
else if((fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) && (appOrientation == UIInterfaceOrientationPortrait)){
// search for exactly the inverse...
}
// must be something more elgant code
CGAffineTransform transform = self.view.transform;
transform = CGAffineTransformRotate(transform, angle);
self.view.transform = transform;
[self.view setBounds:CGRectMake(0, 0, height, width)];
This part of the code it is rotation the screen if is in Landscape and set the size, to match the screen, I don't like the if and the 7x else if. Can you suggest something more readable? Something like (appOrientation - fromInterfaceOrientation) == 2 than angle (M_PI / 2.0)?