coderjoe
coderjoe

Reputation: 147

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.

Upvotes: 0

Views: 1063

Answers (2)

David Rönnqvist
David Rönnqvist

Reputation: 56625

Despite what MDT says, you can actually animate the removal of a view with UIView animation. You just have to use the block-based API that was introduced in iOS 4.

This is the exact sample code from the Apples documentation for transitionWithView:duration:options:animations:completion:

[UIView transitionWithView:containerView
                  duration:0.2
                  options:UIViewAnimationOptionTransitionFlipFromLeft
                  animations:^{
                      [fromView removeFromSuperview];
                      [containerView addSubview:toView]; }
                  completion:NULL];

It will flip from left, removing fromView and adding toView to containerView (the view that they are added removed from).

Upvotes: 1

Mick MacCallum
Mick MacCallum

Reputation: 130193

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];
}

Upvotes: 1

Related Questions