码迷,mamicode.com
首页 > 移动开发 > 详细

iOS开发——雪花下落

时间:2016-06-30 17:47:05      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

用帧动画实现

-(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开发——雪花下落

标签:

原文地址:http://www.cnblogs.com/qinxiaoguang/p/5630440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!