0

I want to animate the transition of my LevelCompletedVC. The LevelCompletedVC should come from Top to Bottom.

Here is my Code in the GameViewController:

LevelCompletedViewController *lcvc = [self.storyboard instantiateViewControllerWithIdentifier:@"levelCompletedViewController"];

[self.view addSubview:lcvc.view];
[lcvc.view setFrame:self.view.window.frame];
[lcvc.view setTransform:CGAffineTransformMakeTranslation(0, -self.view.frame.size.height)];
[lcvc.view setAlpha:1.0];

[UIView animateWithDuration:0.7 delay:0.0 options : UIViewAnimationOptionTransitionFlipFromTop
           animations:^{
                    [lcvc.view setTransform : CGAffineTransformMakeTranslation(0, 0)];
                    [lcvc.view setAlpha:1.0];
           }
           completion:^(BOOL finished) {
                     [lcvc.view removeFromSuperview];
                     [self presentViewController:lcvc animated:NO completion:nil];
       }];

If I want to present the second VC with:

LevelCompletedViewController *lcvc = [self.storyboard instantiateViewControllerWithIdentifier:@"levelCompletedViewController"];


[self presentViewController:lcvc animated:NO completion:nil];

theres no error.

But with my own transition i get:

Unbalanced calls to begin/end appearance transitions for LevelCompletedViewController.

Whats wrong?

Sujay
  • 2,510
  • 2
  • 27
  • 47
Sausagesalad
  • 91
  • 10

1 Answers1

1

I don't know when or where you present the second VC, but i got same wrong before.

In my case, presentViewController are waiting other action done.

Try

dispatch_async(dispatch_get_main_queue(), ^(void){     
    LevelCompletedViewController *lcvc = [self.storyboard instantiateViewControllerWithIdentifier:@"levelCompletedViewController"];
    [self presentViewController:lcvc animated:NO completion:nil];
});

hope this help you.

Reming Hsu
  • 2,215
  • 15
  • 18
  • thank you! it working. can you explain me why? what exactly does dispatch_async(dispatch_get_main_queue() ? – Sausagesalad Jun 26 '15 at 10:18
  • You need to make sure you only call UIKit methods on the main thread. The completion handler isn't guaranteed to be called on any particular thread.See:(http://stackoverflow.com/a/15079316/4971946) and (http://stackoverflow.com/a/8650092/4971946) – Reming Hsu Jun 29 '15 at 02:58