Search code examples
objective-cdelegatesswitchingrootview

Switching view by changing delegate rootViewContoller


I'm presently trying to switch view from a UIViewController to a SplitViewController. I'm currently doing this in my UIViewController:

AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

[UIView transitionWithView:delegate.window duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
    delegate.window.rootViewController = delegate.splitViewController;
} completion:nil];

[self.view removeFromSuperview];

Is it the right way to switch view ? If yes, I still have a problem to solve with that method. It first quickly shows the MasterView in Portrait Mode and then show the whole split view in the current orientation mode of the iPad.

I hope I'm clear enough.

Thank for you help.


Solution

  • I found a way to make it work from that thread :

    RootViewController animation transition, initial orientation is wrong

    AppDelegate *delegate =(AppDelegate *)[[UIApplication sharedApplication] delegate];
    [UIView transitionWithView:self.window duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
        BOOL oldState = [UIView areAnimationsEnabled];
        [UIView setAnimationsEnabled:NO];
        delegate.window.rootViewController = self.splitViewController;
        [UIView setAnimationsEnabled:oldState];
     } 
     completion:nil];