如何递归执行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. 在Ubuntu16.04集群上手工部署Kubernetes

    目前Kubernetes为Ubuntu提供的kube-up脚本,不支持15.10以及16.04这两个使用systemd作为init系统的版本. 这里详细介绍一下如何以非Docker方式在Ubuntu1 ...

  2. python-wsgi测试服务器

    #!/usr/bin/python from wsgiref.simple_server import make_server def application(environ,start_respon ...

  3. unity批量设置图片为etc2格式或者astc格式

    网上找了半天,没一个能用的,干脆自己写个,直接拷贝这个脚本就行 这个是ios版本的,安卓的话写在注释里面,去掉注释就能用了 现在ios支持一种新格式叫astc比原本的pvrtc压缩比更高,而且质量更高 ...

  4. 使用jdk生成ssl证书文件

    java自带有 ssl 证书生成的工具, 在 /bin/keytools.exe 需要确认已经正确配置JAVA_HOME的环境变量 生成服务端证书: keytool -genkey -v -alias ...

  5. JVM的监控命令

    JVM监控命令基本就是 jps.jstack.jmap.jhat.jstat 几个命令的使用就可以了 JDK本身提供了很多方便的JVM性能调优监控工具,除了集成式的VisualVM和jConsole外 ...

  6. MVC5 知识点记录

    http://blog.csdn.net/qinkeliangqin/article/details/27084639#t27 一.概述 MVC简介: •       模型(Model) “数据模型” ...

  7. 图解ARP协议(五)免费ARP:地址冲突了肿么办?

    一.免费ARP概述 网络世界纷繁复杂,除了各种黑客攻击行为对网络能造成实际破坏之外,还有一类安全问题或泛安全问题,看上去问题不大,但其实仍然可以造成极大的杀伤力.今天跟大家探讨的,也是技术原理比较简单 ...

  8. R语言格式化数字和字符串format函数

    数字和字符串可以使用 format()函数的格式化为特定样式. 语法 format()函数的基本语法是: format(x, digits, nsmall,scientific,width,justi ...

  9. 数据库索引--------B/B+树、聚集、非聚集、符合索引

    摘录自博客:http://www.cnblogs.com/morvenhuang/archive/2009/03/30/1425534.html 一.引言 对数据库索引的关注从未淡出我的们的讨论,那么 ...

  10. ViewPager(视图滑动切换工具)

    <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.Cons ...