免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1538 | 回复: 2
打印 上一主题 下一主题

雪花飘落效果 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-02-03 18:36 |只看该作者 |倒序浏览
雪花飘落效果






Ios代码
  1. 1.- (void)viewDidLoad {   
  2. 2.    [super viewDidLoad];   
  3. 3.    flakeImage = [UIImage imageNamed:@"flake.png"];   
  4. 4.    [NSTimer scheduledTimerWithTimeInterval:(0.05) target:self selector:@selector(play) userInfo:nil repeats:YES];   
  5. 5.}   
  6. 6.  
  7. 7.- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {   
  8. 8.    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);   
  9. 9.}   
  10. 10.  
  11. 11.- (void)play {   
  12. 12.    UIImageView *flakeView = [[UIImageView alloc] initWithImage:flakeImage];   
  13. 13.    int startX = round(random() % 1024);   
  14. 14.    int endX = round(random() % 1024);   
  15. 15.    double scale = 1 / round(random() % 100) + 1.0;   
  16. 16.    double speed = 1 / round(random() % 100) + 1.0;   
  17. 17.    flakeView.frame = CGRectMake(startX, -100.0, 25.0 * scale, 25.0 * scale);   
  18. 18.    flakeView.alpha = 0.55;   
  19. 19.    [self.view addSubview:flakeView];      
  20. 20.    [UIView beginAnimations:nil context:flakeView];   
  21. 21.    [UIView setAnimationDuration:5 * speed];   
  22. 22.    flakeView.frame = CGRectMake(endX, 768.0, 25.0 * scale, 25.0 * scale);   
  23. 23.    [UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];   
  24. 24.    [UIView setAnimationDelegate:self];   
  25. 25.    [UIView commitAnimations];   
  26. 26.}   
  27. 27.  
  28. 28.- (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {   
  29. 29.    UIImageView *flakeView = context;   
  30. 30.    [flakeView removeFromSuperview];   
  31. 31.    [flakeView release];   
  32. 32.}  
  33. - (void)viewDidLoad {
  34.     [super viewDidLoad];
  35.         flakeImage = [UIImage imageNamed:@"flake.png"];
  36.         [NSTimer scheduledTimerWithTimeInterval:(0.05) target:self selector:@selector(play) userInfo:nil repeats:YES];
  37. }

  38. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  39.         return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
  40. }

  41. - (void)play {
  42.         UIImageView *flakeView = [[UIImageView alloc] initWithImage:flakeImage];
  43.         int startX = round(random() % 1024);
  44.         int endX = round(random() % 1024);
  45.         double scale = 1 / round(random() % 100) + 1.0;
  46.         double speed = 1 / round(random() % 100) + 1.0;
  47.         flakeView.frame = CGRectMake(startX, -100.0, 25.0 * scale, 25.0 * scale);
  48.         flakeView.alpha = 0.55;
  49.         [self.view addSubview:flakeView];       
  50.         [UIView beginAnimations:nil context:flakeView];
  51.         [UIView setAnimationDuration:5 * speed];
  52.         flakeView.frame = CGRectMake(endX, 768.0, 25.0 * scale, 25.0 * scale);
  53.         [UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
  54.         [UIView setAnimationDelegate:self];
  55.         [UIView commitAnimations];
  56. }

  57. - (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {       
  58.         UIImageView *flakeView = context;
  59.         [flakeView removeFromSuperview];
  60.         [flakeView release];
  61. }
复制代码
示例图:

论坛徽章:
0
2 [报告]
发表于 2012-02-03 18:36 |只看该作者
谢谢分享

论坛徽章:
0
3 [报告]
发表于 2012-02-29 14:15 |只看该作者
不错,考虑下怎么用Android实现。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP