iOS开发——雪花下落
Posted qinxiaoguang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS开发——雪花下落相关的知识,希望对你有一定的参考价值。
用帧动画实现
-(void)goCome { timer =[NSTimer scheduledTimerWithTimeInterval:0.6 target:self selector:@selector(go) userInfo:nil repeats:YES]; } -(void)go { //动画效果 UIImageView *iv = [[UIImageView alloc]init]; int a = arc4random()%51;//雪花大小随机(0~50) iv.frame = CGRectMake(arc4random()%370 - 50, -50, a, a); iv.image = [UIImage imageNamed:@"3"]; [self.view addSubview:iv]; [UIView beginAnimations:nil context:(__bridge void *)(iv)]; [UIView setAnimationDuration:3]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; iv.frame = CGRectMake(arc4random()%370 - 50, 460, a, a); [UIView commitAnimations]; } -(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context//到底部消除 { UIImageView *image = (__bridge UIImageView *)context; [image removeFromSuperview]; }
以上是关于iOS开发——雪花下落的主要内容,如果未能解决你的问题,请参考以下文章