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

 

posted @ 2016-06-30 16:32  qinxiaoguang  阅读(234)  评论(0编辑  收藏  举报