飘雪花动画
该飘雪动画实现思路:
1.雪花用的图片。
2.下雪的动作是用的view层实现的,用view实现一个下落的动作。
3.应用算法实现随机时间,然后创建相应的雪花,实现下降。
部分代码:
- (void)ontime{
UIImageView * view;
view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"xuehua.jpg"]];
view.alpha = 0.5;
int x = round(random() % 320);
int y = round(random() % 320);
int s = round(random() % 15) + 10;
int sp = 1 / round(random() % 100) + 1;
view.frame = CGRectMake(x, y - 250, s, s);
[self.view addSubview:view];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:10 * sp];
view.frame = CGRectMake(x, 500, s, s);
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
}
代码地址:https://github.com/ChangYulong/SnowDemo