1
votes

I am using a tab bar controller for my app. If I'm in one of the view controllers called "results" and the ios device rotates to landscape mode, it switches for another view I created called landScape. This has been done within the method

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrient‌​ation duration:(NSTimeInterval)duration
{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight ||
        toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    {
        self.view=landScape;
    } else {
        self.view=originalView;
    }
}

It works just fine whenever I am in that specific controller within the tab bar (example results view controller). However; If I go to another element in my tab bar controller and my phone is tilted in landscape mode and then I decide to go to resultsviewcontroller, it does not call upon my view landScape, instead it tries to autosize the view on its own and it looks awful. Should I call the method -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration within my viewDidLoad method to solve the problem? Or is this completely wrong?

Thank you in advance!

1

1 Answers

2
votes

The problem is you're only setting resultsViewController.view when it is the active view controller and detects a rotation. Try this:

- (void)setViewForInterfaceOrientation:(UIInterfaceOrientation)orientation
{
    self.view = UIInterfaceOrientationIsPortrait(orientation)
        ? originalView
        : landScape;
}

- (void)viewWillAppear
{
    [self setViewForInterfaceOrientation:[[UIDevice currentDevice] orientation];
    [super viewWillAppear];
}

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrient‌​ation duration:(NSTimeInterval)duration
{
    [self setViewForInterfaceOrientation:toInterfaceOrientation];
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}