0

I have a master detail application that when the detail view appears and a string is empty, I want it to present a new view through a UIViewAnimationFlip. The animation is working, but it keeps flipping to itself, not the view controller I initiated. Any help would be great!

- (void)viewDidAppear:(BOOL)animated {

    if (masterView.parserURL == nil) {

        LoginViewController *login = [[LoginViewController alloc] init];

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.8];
        [UIView setAnimationTransition:UIModalTransitionStyleFlipHorizontal
                               forView:self.view
                                 cache:YES];

        [self.navigationController presentViewController:login 
                                                animated:YES 
                                              completion:nil];

        [UIView commitAnimations];
    }
}
Bartosz Ciechanowski
  • 10,293
  • 5
  • 45
  • 60
Jon Erickson
  • 1,876
  • 4
  • 30
  • 73
  • IMHO, one shouldn't be doing `addSubview` unless doing view controller containment. I'd set `modalTransitionStyle` of `UIModalTransitionStyleFlipHorizontal`; and then replace the `addSubview` line with a [`presentViewController`](http://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/presentViewController:animated:completion:). When you want to return, the child would do `dismissViewControllerAnimated`. – Rob Dec 13 '12 at 20:01
  • I changed to like how you said and now it does the animation to a black screen! – Jon Erickson Dec 13 '12 at 20:04
  • @JonErickson See my answer below and see if that helps you – Eric Dec 13 '12 at 21:03

2 Answers2

1

I agree that you should be doing this modally, instead of just adding a subview. In your example code you are animating twice, because the presentviewcontroller method is animating itself already. Try removing the other animation code as follows:

LoginViewController *login = [[LoginViewController alloc] init];
login.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[self presentViewController:login 
                   animated:YES 
                 completion:nil];
Eric
  • 5,671
  • 5
  • 31
  • 42
0

I'm suggesting simply:

- (void)viewDidAppear:(BOOL)animated {

    if (masterView.parserURL == nil) {

        LoginViewController *login = [[LoginViewController alloc] init];

        login.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

        [self presentViewController:login
                           animated:YES
                         completion:nil];
    }
}

Note, there's an interesting question of how the login screen is supposed to update that parserURL field in masterView. You might add a property to your login controller that is a pointer to masterView, so that it has a mechanism to update the parserURL. Thus it might be like:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    if (masterView.parserURL == nil)
    {
        LoginViewController *login = [[LoginViewController alloc] init];

        login.masterView = masterView;

        login.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

        [self presentViewController:login
                           animated:YES
                         completion:nil];
    }
}

Then your login controller can now update the parserURL via:

self.masterView.parserURL = ... // set it as appropriate
Rob
  • 415,655
  • 72
  • 787
  • 1,044