如何递归执行view的动画
如何递归执行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的动画的更多相关文章
- 同时对view延时执行两个动画时候的现象
同时对view延时执行两个动画时候的现象 对于view延时执行了两个动画后,会将第一个动画效果终止了,直接在第一个动画的view的最后的状态上接执行后续的动画效果,也就是说,我们可以利用这个特性来写分 ...
- 多文件目录下makefile文件递归执行编译所有c文件
首先说说本次嵌套执行makefile文件的目的:只需make根目录下的makefile文件,即可编译所有c文件,包括子目录下的. 意义:自动化编译行为,以后编译自己的c文件时可把这些makefile文 ...
- 【转】多文件目录下makefile文件递归执行编译所有c文件
首先说说本次嵌套执行makefile文件的目的:只需make根目录下的makefile文件,即可编译所有c文件,包括子目录下的. 意义:自动化编译行为,以后编译自己的c文件时可把这些makefile文 ...
- 算法笔记_017:递归执行顺序的探讨(Java)
目录 1 问题描述 2 解决方案 2.1 问题化简 2.2 定位输出测试 2.3 回顾总结 1 问题描述 最近两天在思考如何使用蛮力法解决旅行商问题(此问题,说白了就是如何求解n个不同字母的所有不同排 ...
- 用同步的方式执行jQuery异步动画
在编写jQuery动画时,通过回调函数进行动画队列的编排,但当回调过多,往往会出现这样的代码: $(".box1").fadeIn(1000,function(){ $(" ...
- 看完这篇再不会 View 的动画框架,我跪搓衣板
引言 众所周知,一款没有动画的 app,就像没有灵魂的肉体,给用户的体验性很差.现在的 android 在动画效果方面早已空前的发展,1.View 动画框架 2.属性动画框架 3.Drawable 动 ...
- iOS的view翻转动画实现--代码老,供参考
新建一个view-based模板工程,在ViewController文件中添加下面的代码,即可实现翻转效果: - (void)viewDidLoad { [super viewDidLoad]; // ...
- Android添加系统级顶层窗口 和 WindowManager添加view的动画问题
当Dialog有编辑框时如果选择会弹菜单窗口就不要用 Context applicationContext = mainActivity.getApplicationContext(); AlertD ...
- Makefile笔记之二------make的递归执行
1.make的递归过程指的是: 在Makefile中使用"make"作为一个命令来执行本身或者其它makefile文件的过程. 2.递归的意义: 当前目录下存在一个"su ...
随机推荐
- Java程序员的面试经历和题库
最近打算换城市了,受不了北京的雾霾了,所以准备逃离啦.所以一直在面试中,整理了下最近遇到的一些面试题,供大家参考.其中会包含一些面试的小经验,如果您是面霸,希望能给予指导.自己不是大牛,如果您是大牛, ...
- JavaScript设计模式-10.工厂模式实例xhr
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Java 实现两个整数变量的交换
class OperatorTest { public static void main(String[] args) { int a = 10; int b = 20; System.out.pri ...
- Scrum 冲刺博客第四篇
一.当天站立式会议照片一张 二.每个人的工作 (有work item 的ID),并将其记录在码云项目管理中 昨天已完成的工作 新建立了一个list页面用来显示题目,并且创建了列表用来进行题目的存放,将 ...
- 原生javascript实现分页效果+搜索功能
一.概述 首先,我们要明确为何需要分页技术,主要原因有以下: 1.分页可以提高客户体验度,适当地选择合适的数据条数,让页面显得更有条理,使得用户体验感良好,避免过多数据的冗余. 2.提高性能的需要. ...
- HandlerInterceptor与MethodInterceptor
HandlerInterceptor是springMVC项目中的拦截器,它拦截的目标是请求的地址,比MethodInterceptor先执行.实现一个HandlerInterceptor拦截器可以直接 ...
- jquery对象与dom对象之间互相转换的方法
本文主要讲述jquery对象和js里的dom对象之间互相转换的方法,使jquery对象可以直接使用js里的方法,或js里的dom对象使用jquery里的方法. jquery对象和dom对象是不一样的, ...
- 撩课-Java每天10道面试题第2天
11.面向对象的特征有哪些方面 1.抽象: 抽象就是忽略一个主题中与当前目标无关的那些方面, 以便更充分地注意与当前目标有关的方面. 抽象并不打算了解全部问题,而只是选择其中的一部分, 暂时不用部分细 ...
- Java8实战Lambda和Stram API学习
public class Trader{ private String name; private String city; public Trader(String n, St ...
- ubuntu关机重启命令
重启命令 : 1.reboot 2.shutdown -r now 立刻重启 3.shutdown -r 10 过10分钟自动重启 4.shutdown -r 20:35 ...