开发者

Is it possible to removeFromSuperview with Animation?

开发者 https://www.devze.com 2022-12-11 06:42 出处:网络
I have 2 layer is top and bottom on my program how can i remove top layer with animation or bring top layer to back i开发者_C百科s it possible? The easiest is playing with frame and alpha before remo

I have 2 layer is top and bottom on my program

how can i remove top layer with animation or bring top layer to back i开发者_C百科s it possible?


The easiest is playing with frame and alpha before removing it.

You can get some cool effects

-(void)removeWithEffect:(UIView *)myView
{
 [UIView beginAnimations:@"removeWithEffect" context:nil];
 [UIView setAnimationDuration:0.5f];
 //Change frame parameters, you have to adjust
 myView.frame = CGRectMake(0,0,320,480);
 myView.alpha = 0.0f;
 [UIView commitAnimations];
 [myView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.5f];
}

iOS Update

You can now use blocks to perform your animation

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


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

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

(above code comes from Apple's UIView documentation)

0

精彩评论

暂无评论...
验证码 换一张
取 消