zoukankan      html  css  js  c++  java
  • NSTimer与iphone的简单动画

    使用使用NSTimer与iphone的简单动画,实现飘雪效果,这理原理比较简单,就是定时生成一定的雪花图片,然后使用动画的方式向下漂落(我在其它论坛,看到使用path的方式实现的一个云漂来漂去的效果,实际也可以用那种方式实现,这实际就是前面说的动画效果的两种应用)。所以,我们可以在viewDidLoad事件中,增加一个图片及定时器并启动,这里的pic请在头文件中定义。

    -(void)viewDidLoad{  [super viewDidLoad];  self.pic = [UIImage imageNamed:@"snow.png"];//初始化图片  //启动定时器,实现飘雪效果  [NSTimer scheduledTimerWithTimeInterval:(0.2) target:self selector:@selector(ontime) userInfo:nil repeats:YES]; }

    然后再实现定时器定时调用的ontime方法:

    -(void)ontime{  UIImageView *view = [[UIImageView alloc] initWithImage:pic];//声明一个UIImageView对象,用来添加图片  view.alpha = 0.5;//设置该view的alpha为0.5,半透明的  int x = round(random()%320);//随机得到该图片的x坐标  int y = round(random()%320);//这个是该图片移动的最后坐标x轴的  int s = round(random()%15)+10;//这个是定义雪花图片的大小  int sp = 1/round(random()%100)+1;//这个是速度  view.frame = CGRectMake(x, -50, s, s);//雪花开始的大小和位置  [self.view addSubview:view];//添加该view  [UIView beginAnimations:nil context:view];//开始动画  [UIView setAnimationDuration:10*sp];//设定速度  view.frame = CGRectMake(y, 500, s, s);//设定该雪花最后的消失坐标  [UIView setAnimationDelegate:self];  [UIView commitAnimations]; }
    标签: IphoneNSTimerUIImageView
    ,实现飘雪效果,这理原理比较简单,就是定时生成一定的雪花图片,然后使用动画的方式向下漂落(我在其它论坛,看到使用path的方式实现的一个云漂来漂去的效果,实际也可以用那种方式实现,这实际就是前面说的动画效果的两种应用)。所以,我们可以在viewDidLoad事件中,增加一个图片及定时器并启动,这里的pic请在头文件中定义。

    -(void)viewDidLoad{  [super viewDidLoad];  self.pic = [UIImage imageNamed:@"snow.png"];//初始化图片  //启动定时器,实现飘雪效果  [NSTimer scheduledTimerWithTimeInterval:(0.2) target:self selector:@selector(ontime) userInfo:nil repeats:YES]; }

    然后再实现定时器定时调用的ontime方法:

    -(void)ontime{  UIImageView *view = [[UIImageView alloc] initWithImage:pic];//声明一个UIImageView对象,用来添加图片  view.alpha = 0.5;//设置该view的alpha为0.5,半透明的  int x = round(random()%320);//随机得到该图片的x坐标  int y = round(random()%320);//这个是该图片移动的最后坐标x轴的  int s = round(random()%15)+10;//这个是定义雪花图片的大小  int sp = 1/round(random()%100)+1;//这个是速度  view.frame = CGRectMake(x, -50, s, s);//雪花开始的大小和位置  [self.view addSubview:view];//添加该view  [UIView beginAnimations:nil context:view];//开始动画  [UIView setAnimationDuration:10*sp];//设定速度  view.frame = CGRectMake(y, 500, s, s);//设定该雪花最后的消失坐标  [UIView setAnimationDelegate:self];  [UIView commitAnimations]; }
    标签: IphoneNSTimerUIImageView
  • 相关阅读:
    css overflow失效的原因
    css3过渡动画 transition
    css3动画 2D 3D transfrom
    百度前端学院第7-8天笔记,百度前端学院系统维护,所以转战仿京东项目。
    position 的absolute会使display变成inline-block
    css 布局 flex
    sqli-labs lesson5-6 布尔盲注 报错注入 延时注入
    sqli-labs lesson1-4
    有关SQL注入的一些小知识点
    DVWA(三):SQL injection 全等级SQL注入
  • 原文地址:https://www.cnblogs.com/moonvan/p/2228620.html
Copyright © 2011-2022 走看看