Question

Here's my issue: My app has a toolbar where you can change between views. The main one or at least the one on launch is in on landscape mode, then if you go to any other view is in portrait. The problem comes when you try to go back to the first one (landscape), the view appears in portrait, therefore all view is wrong displayed. (Is it more or less clear? sorry if seems messy). Some code I have here:

V1Controller:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

V2Controller:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(IBAction)goToV1 {
 V1Controller *v1 = [[V1Controller alloc] init];
 [self.view.superview addSubview:v1.view];
}

Maybe do something with the object v1 before adding the view? I don't know, need your help.

Problem solved In the view transition I was missing one sentence, remove the current view from the superview. Also what @Brad was saying. Thank you.

-(IBAction)goToV1 {
     V1Controller *v1 = [[V1Controller alloc] init];
     [self.view.superview addSubview:v1.view];
     [self.view removeFromSuperview];
    }
Was it helpful?

Solution

When you say:

return (interfaceOrientation == UIInterfaceOrientationPortrait);

Your are allowing it to be rotated only to portrait.

If you want to rotate to portrait and then back to landscape, just return "YES".

The same logic applies when you say

return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);

You are effectively saying: "Let it be rotated one way - but never back the other way"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top