如何递归执行view的动画

效果:

山寨的源头:

图片素材:

源码:

//
// ViewController.m
// RepeatAnimationView
//
// Created by YouXianMing on 15/1/30.
// Copyright (c) 2015年 YouXianMing. All rights reserved.
// #import "ViewController.h" @interface ViewController () @property (nonatomic, strong) UIImageView *imageView; @property (nonatomic) CGRect startRect;
@property (nonatomic) CGRect centerRect;
@property (nonatomic) CGRect endRect; @property (nonatomic) CGFloat distanceFromStartToCenter;
@property (nonatomic) CGFloat distanceFromCenterToEnd; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; self.distanceFromStartToCenter = .f;
self.distanceFromCenterToEnd = .f; // 背景色
self.view.backgroundColor = [UIColor blackColor]; // 红色图片
self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"red"]];
self.imageView.center = self.view.center;
self.imageView.alpha = ;
[self.view addSubview:self.imageView]; // 设置rect
self.startRect = self.imageView.frame; CGRect tmpRect = self.startRect;
tmpRect.origin.y -= self.distanceFromStartToCenter;
self.centerRect = tmpRect; tmpRect = self.centerRect;
tmpRect.origin.y -= self.distanceFromCenterToEnd;
self.endRect = tmpRect; // 递归调用
[self doAnimation];
} - (void)doAnimation {
[UIView animateWithDuration:.f
delay:0.2f
options:UIViewAnimationOptionCurveEaseInOut
animations:^{ self.imageView.alpha = .f;
self.imageView.frame = self.centerRect; } completion:^(BOOL finished) { [UIView animateWithDuration:0.5f
delay:0.1f
options:UIViewAnimationOptionCurveEaseInOut
animations:^{ self.imageView.alpha = .f;
self.imageView.frame = self.endRect; } completion:^(BOOL finished) { self.imageView.frame = self.startRect;
[self doAnimation];
}];
}];
} @end
//
// ViewController.m
// RepeatAnimationView
//
// Created by YouXianMing on 15/1/30.
// Copyright (c) 2015年 YouXianMing. All rights reserved.
// #import "ViewController.h" @interface ViewController () @property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIImageView *cyanView; @property (nonatomic) CGRect startRect;
@property (nonatomic) CGRect centerRect;
@property (nonatomic) CGRect endRect; @property (nonatomic) CGFloat distanceFromStartToCenter;
@property (nonatomic) CGFloat distanceFromCenterToEnd; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; self.distanceFromStartToCenter = .f;
self.distanceFromCenterToEnd = .f; // 背景色
self.view.backgroundColor = [UIColor blackColor]; // 红色图片
self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"red"]];
self.imageView.center = self.view.center;
self.imageView.alpha = ;
[self.view addSubview:self.imageView]; self.cyanView = [[UIImageView alloc] initWithFrame:self.imageView.bounds];
self.cyanView.image = [UIImage imageNamed:@"cyan"];
[self.imageView addSubview:self.cyanView]; // 设置rect
self.startRect = self.imageView.frame; CGRect tmpRect = self.startRect;
tmpRect.origin.y -= self.distanceFromStartToCenter;
self.centerRect = tmpRect; tmpRect = self.centerRect;
tmpRect.origin.y -= self.distanceFromCenterToEnd;
self.endRect = tmpRect; // 递归调用
[self doAnimation];
} - (void)doAnimation {
[UIView animateWithDuration:.f
delay:0.2f
options:UIViewAnimationOptionCurveEaseInOut
animations:^{ self.imageView.alpha = .f;
self.imageView.frame = self.centerRect;
self.cyanView.alpha = 0.5; } completion:^(BOOL finished) { [UIView animateWithDuration:0.5f
delay:0.1f
options:UIViewAnimationOptionCurveEaseInOut
animations:^{ self.imageView.alpha = .f;
self.imageView.frame = self.endRect;
self.cyanView.alpha = .f; } completion:^(BOOL finished) { self.imageView.frame = self.startRect;
self.cyanView.alpha = .f;
[self doAnimation];
}];
}];
} @end

如何递归执行view的动画的更多相关文章

  1. 同时对view延时执行两个动画时候的现象

    同时对view延时执行两个动画时候的现象 对于view延时执行了两个动画后,会将第一个动画效果终止了,直接在第一个动画的view的最后的状态上接执行后续的动画效果,也就是说,我们可以利用这个特性来写分 ...

  2. 多文件目录下makefile文件递归执行编译所有c文件

    首先说说本次嵌套执行makefile文件的目的:只需make根目录下的makefile文件,即可编译所有c文件,包括子目录下的. 意义:自动化编译行为,以后编译自己的c文件时可把这些makefile文 ...

  3. 【转】多文件目录下makefile文件递归执行编译所有c文件

    首先说说本次嵌套执行makefile文件的目的:只需make根目录下的makefile文件,即可编译所有c文件,包括子目录下的. 意义:自动化编译行为,以后编译自己的c文件时可把这些makefile文 ...

  4. 算法笔记_017:递归执行顺序的探讨(Java)

    目录 1 问题描述 2 解决方案 2.1 问题化简 2.2 定位输出测试 2.3 回顾总结 1 问题描述 最近两天在思考如何使用蛮力法解决旅行商问题(此问题,说白了就是如何求解n个不同字母的所有不同排 ...

  5. 用同步的方式执行jQuery异步动画

    在编写jQuery动画时,通过回调函数进行动画队列的编排,但当回调过多,往往会出现这样的代码: $(".box1").fadeIn(1000,function(){ $(" ...

  6. 看完这篇再不会 View 的动画框架,我跪搓衣板

    引言 众所周知,一款没有动画的 app,就像没有灵魂的肉体,给用户的体验性很差.现在的 android 在动画效果方面早已空前的发展,1.View 动画框架 2.属性动画框架 3.Drawable 动 ...

  7. iOS的view翻转动画实现--代码老,供参考

    新建一个view-based模板工程,在ViewController文件中添加下面的代码,即可实现翻转效果: - (void)viewDidLoad { [super viewDidLoad]; // ...

  8. Android添加系统级顶层窗口 和 WindowManager添加view的动画问题

    当Dialog有编辑框时如果选择会弹菜单窗口就不要用 Context applicationContext = mainActivity.getApplicationContext(); AlertD ...

  9. Makefile笔记之二------make的递归执行

    1.make的递归过程指的是: 在Makefile中使用"make"作为一个命令来执行本身或者其它makefile文件的过程. 2.递归的意义: 当前目录下存在一个"su ...

随机推荐

  1. redis有序集合类型sort set

    redis的数据类型之-有序集合 sort set和set类型一样,也是string类型元素的集合,也没有重复的元素,不同的是sort set每个元素都会关联一个权,通过权值可以有序的获取集合中的元素 ...

  2. ERROR 1064 (42000): You have an error in your SQL syntax;

    出现: ERROR 1064 (42000): You have an error in your SQL syntax; 1.SQL语句拼写错误. 具体很简单.慢慢查看 2.使用到了SQL关键字. ...

  3. selector.select()和selector.selectedKeys()

    当调用selector.select()时会阻塞: This method performs a blocking selection operation. It returns only after ...

  4. Lineare Algebra

    Grundlegendes Wort: 矩阵列:Das Spalte von der Matrix 行列式:Die Determinante 对角矩阵:Die diagonal Matrix 逆矩阵: ...

  5. Angular2 不明真相第一个Demo例子

    如果不是去年换工作接触到AngularJS,估计是不会花时间去学习这个框架的,毕竟是前端的框架,不是自己熟悉的领域.但是为了混得下去,去年就学习了AngularJS的一些用法,当时还整理了一些积累 & ...

  6. 私有字段private也可以外部访问

    <?php//私有字段private也可以外部访问class nowamagic { private $domain; function __get($key){ return "使用 ...

  7. SQL:存储过程

    1/什么是存储过程及概念 Transact-SQL中的存储过程,非常类似于.Net语言中的方法,它可以重复调用.当存储过程执行一次后,可以将语句缓存中,这样下次执行的时候直接使用缓存中的语句.这样就可 ...

  8. [学习线路] 零基础学习hadoop到上手工作线路指导(初级篇)

    about云课程最新课程Cloudera课程   零基础学习hadoop,没有想象的那么困难,也没有想象的那么容易.在刚接触云计算,曾经想过培训,但是培训机构的选择就让我很纠结.所以索性就自己学习了. ...

  9. centos 网络很慢且无法远程登陆的解决办法

    安装了centOS,但是发现网速实在是卡得几乎不能上网,连百度都打不开 后来想到偶然记得有一次看过一段话,说到关闭ipv6,测试来一下,果然有效,关闭来ipv6打开网速飞快. 关闭方法,在/etc/m ...

  10. 搭建和启动javaWeb项目

    首先,我们得配置服务器,我的demo采用tomcat 你只要找到tomcat的home路径就好了,后面会自动给你提示的