Search code examples
xcodeipaduiviewcore-animation

Removing superview is already done before animation


I have an app where a movie view is a kind of loading screen, and it's on top of my root controller, splitViewController. When the movie has finished, i want to remove it from the superview, animated. I'm using this code now, where mpmctr my movie controller is:

[UIView beginAnimations:@"blablablab" context:NULL];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:splitViewController.view.superview cache:NO];
[UIView setAnimationDuration:.5];
[mpMCtr.view removeFromSuperview];
[UIView commitAnimations];

When this code runs, mpmctr removes itself from the superview but not animated. This is happening when the splitviewcontroller is already on the screen.

Im using this code for putting mpmctr on the view in the delegate method didfinishlaunching.

[window addSubview:splitViewController.view];
[splitViewController.view addSubview:mpMCtr.view];

I hope that you guys can help me with this problem,

Thanks in advance.


Solution

  • A UIView animation can't animate removal from superview, but you could for example animate its alpha down to zero, then you could do this to remove the view after your animation has completed.

    [UIView setAnimationDidStopSelector:@selector(removeMyView)];
    
    
    - (void) removeMyView
    {
    
        [mpMCtr.view removeFromSuperview];
    }