View Controller A displays View Controller B in horizontal orientation
#pragma mark Rotation Delegate Methods
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return YES;
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
[landscapeChartViewController.chartImageView reloadWithUrl:
[NSString stringWithFormat:@"someurl",[symbol uppercaseString]]];
NSLog(@"showing chart");
[self presentModalViewController:landscapeChartViewController animated:NO];
}
}
This works fine. View Controller B shows up in landscape orientation. Here is View Controller B’s implementation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
NSLog(@"dismissing chart");
[self.parentViewController dismissModalViewControllerAnimated:NO];
}
}
The problem is, when I go back into portrait orientation to show View Controller A, View Controller A is stuck in landscape orientation. How can I fix this?
EDIT: after reading your comment, I suggest trying to use
willRotateToInterfaceOrientation:duration:instead ofwillAnimateRotationToInterfaceOrientation, like this:controller A:
controller B:
I do more or less the same in a project of mine, only between two non modal views.