• iOS飘雪的动画小demo


    1 ViewController.h
    2 
    3 #import <UIKit/UIKit.h>
    4 
    5 @interface ViewController : UIViewController{
    6     UIImage* flakeImage;
    7 }
    8 - (void)onTimer;
    9 @end
     1 ViewController.m
     2 
     3 #import "ViewController.h"
     4 
     5 @interface ViewController ()
     6 
     7 @end
     8 
     9 @implementation ViewController
    10 
    11 - (void)viewDidLoad
    12 {
    13     [super viewDidLoad];
    14     self.view.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:1.0 alpha:1.0];
    15     flakeImage = [UIImage imageNamed:@"2.png"];
    16     [NSTimer scheduledTimerWithTimeInterval:(0.05) target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
    17 }
    18 - (void)onTimer
    19 {
    20     //创建图像视图对象
    21     UIImageView* flakeView = [[UIImageView alloc] initWithImage:flakeImage];
    22     
    23     int startX = round(random() % 320);
    24     int endX = round(random() % 320);
    25     double scale = 1 / round(random() % 100) + 1.0;
    26     double speed = 1 / round(random() % 100) + 1.0;
    27     flakeView.frame = CGRectMake(startX, -100.0, 25.0 * scale, 25.0 * scale);
    28     flakeView.alpha = 0.5;
    29     [self.view addSubview:flakeView];
    30     [UIView beginAnimations:nil context:(__bridge void *)(flakeView)];
    31     [UIView setAnimationDuration:5 * speed];
    32     flakeView.frame = CGRectMake(endX, 540.0, 25.0 * scale, 25.0 * scale);
    33     [UIView commitAnimations];
    34     
    35 }
    36 
    37 
    38 - (void)didReceiveMemoryWarning
    39 {
    40     [super didReceiveMemoryWarning];
    41     // Dispose of any resources that can be recreated.
    42 }

    图片素材,通过Main.storyboard设置背景图片

  • 相关阅读:
    使用python,批量生产条形码
    excel——VlookUp函数的使用
    MQTT消息队列压力测试
    shell脚本中,关于if,以及条件判断
    linux下的echo
    python对文件操作 r w a 文件复制/修改
    使用Appium进行iOS的真机自动化测试
    pycharm 解决PEP8问题,配置autopep8到菜单栏
    Python中list的合并
    Centos最小化安装后,不能使用yum命令的解决办法
  • 原文地址:https://www.cnblogs.com/henusyj-1314/p/5491378.html
Copyright © 2020-2023  润新知