views:

158

answers:

2

Hello,

I am working on an app (my first one), which is basically a TabBar app. To be more precise there are: - a login view controller - a tab bar controller (when login is done) - a landscape view controller that is used when the first itel of the TabBar is switch from Portrait to Landscape.

So, when I am in the first tab, I need to be able to move to landscape view to display some other data. In my tab bar controller, I have implemented those methods:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if([self selectedIndex] == 0)
    return YES;

return NO;
}


- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];

// Get AppDelegate
MyAppDelegate *delegate = [[UIApplication sharedApplication] delegate];

 if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
 {
     // Remove TabBarView and add graph Landscape View   
     [self.view removeFromSuperview];
     [delegate setSubViewLandscapeViewController];
 }
}

In the delegate, I have implemented the setSubViewLandscapeViewController and the setSubViewTabBarController:

- (void)setSubViewTabBarViewController {    
[window addSubview:[tabBarController view]];
}

- (void)setSubViewGraphLandscapeViewController {
[window addSubview:[landscapeViewController view]];
}

I want the landscapeViewController to display only in landscape mode, I have then (in my landscapeViewController):

- (void)viewWillAppear:(BOOL)animated {
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

NSLog(@"willRotateToInterfaceOrientation");
}

A part of this works fine, I mean the switch from portrait to landscape is ok (when I am in the first tab), the tabbarcontroller is remove from the SuperView and the landscape view is added as a subview instead.

The thing is... I do not know how to switch back to portrait mode (and then load the previous controller, the tabBar one using the setSubViewTabBarViewController of my delegate). It seems none of the willRotateToOrientation, willRotateFromOrientation, .. are triggered when I actually move the device from the landscape view...

In short, when I am in the landscape view I do not know what to do to move back to the tabbar view... I am kind of stuck in the landscape view once I am in this one.

Thanks a lot for your help,

Luc

A: 

Look at the pie chart in CPTestApp-iPhone in the examples folder. It handles rotation by implementing -(void)didRotateFromInterfaceOrientation: and resizing the graph after a rotation.

Eric Skroch
Hello, well in fact I think I was not really clear :(I needed to load an lanscape view when moving from portrait mode to landscape mode, I finnaly managed to to this with the shouldAutorotateToInterfaceOrientation and willRotateToInterfaceOrientation methods. The thing is, now I am in landscape mode I do not know how to handle the rotation from landscape mode to portrait mode... As I have declared the UIView as landscape only, is there a method triggered in this case ? Thanks a lot
Luc
A: 

Well, I managed to get a solution for this problem. In fact, while moving from portrait to landscape I removed the tabbarcontroller from window subview and add the landscapeviewcontroller instead. It seems it was not the correct thing to do. Instead, I add the landscapeViewController as subview of the tabbarcontroller and remove it when going from landscape to portrait. I still have a problem however with the y position of the landscape view which seems to changes when I do several decive rotation in a row.... Regards, Luc

Luc