views:

295

answers:

0

So I have an app with a tab bar, each bar contains a UINavigationController. When user shakes the device, a UIImageView appears as a subview of the nav controller. But the app has a landscape view as well. If the UIImageView is active in portrait mode and user rotates the device, this code works:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)

interfaceOrientation duration:(NSTimeInterval)duration { 

if (interfaceOrientation == UIInterfaceOrientationPortrait) { 
self.view = self.portrait; 

self.view.transform = CGAffineTransformIdentity;
self.view.transform =  CGAffineTransformMakeRotation(degreesToRadians(0));       self.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);

} 
else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) { 

self.view = self.landscape; 
self.view.transform = CGAffineTransformIdentity; 
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); 
self.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);
} 
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { 

self.view = self.portrait; 
self.view.transform = CGAffineTransformIdentity; 
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(180)); 
self.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);
} 
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) { 

self.view = self.landscape; 
self.view.transform = CGAffineTransformIdentity; 
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); 
self.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);
}

}

But if user rotated the device in a nav controller before shaking the device, the UIImageView shows portrait image in landscape, what looks crazy.

Implementing the rotation in UITabBar delegate doesn't help too, because this way, in landscape mode landscape UIImageView is shown, even if user didn't shake the device.

Thanks in advance!