Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animating removeFromSuperview

I'd like to animate the transition from a subview back to the super view.

I display the subview using:

[UIView beginAnimations:@"curlup" context:nil]; [UIView setAnimationDelegate:self]; [UIView setAnimationDuration:.5]; [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES]; [self.view addSubview:self.mysubview.view]; [UIView commitAnimations]; 

The above works fine. It's going back to the super view that I don't get any animation:

[UIView beginAnimations:@"curldown" context:nil]; [UIView setAnimationDelegate:self]; [UIView setAnimationDuration:.5]; [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES]; [self.view removeFromSuperview]; [UIView commitAnimations]; 

Is there something different I should be doing to get the subview to animate when removed?

like image 593
user230949 Avatar asked Jan 05 '10 05:01

user230949


2 Answers

If you're targeting iOS 4.0 upwards you can use animation blocks instead:

[UIView animateWithDuration:0.2      animations:^{view.alpha = 0.0;}      completion:^(BOOL finished){ [view removeFromSuperview]; }]; 

(above code comes from Apple's UIView documentation)

like image 139
JosephH Avatar answered Oct 02 '22 01:10

JosephH


I think you need to do forView:self.view.superview instead, to be consistent with what you are doing when you are adding, because in this case the self.view is the child, and so you would need to do it on the parent.

like image 42
newacct Avatar answered Oct 02 '22 01:10

newacct