IOS中的动画——Core Animation
| 一、基础动画 CABasicAnimation |
//初始化方式
CABasicAnimation * cabase=[CABasicAnimation animation];
//通过keyPath设置需要实现动画的属性,此处设为bounds
cabase.keyPath=@"bounds";
//通过toValue设置动画结束时候的状态
cabase.toValue=[NSValue valueWithCGRect:CGRectMake(, , , )];
//通过byValue设置每次改变的范围
cabase.byValue=[NSValue valueWithCGRect:CGRectMake(, , , )];
//设置开始时候的状态
cabase.fromValue=[NSValue valueWithCGPoint:CGPointMake(, )]; //设置动画持续的时间
cabase.duration=;
//保存动画
cabase.fillMode=kCAFillModeForwards;
//保存设置不取消
cabase.removedOnCompletion=NO;
[_layer addAnimation:cabase forKey:nil];
案例:通过基础动画实现仿射变换动画
CABasicAnimation * cabase=[CABasicAnimation animation];
cabase.keyPath=@"transform";
cabase.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeScale(, , )];
cabase.duration=;
cabase.fillMode=kCAFillModeForwards; cabase.removedOnCompletion=NO;
[_layer addAnimation:cabase forKey:nil];
| 二、关键帧动画 |
//初始化方式
CAKeyframeAnimation * keyfram=[CAKeyframeAnimation animation];
//通过keyPath设置需要实现动画的属性,此处设为position
keyfram.keyPath=@"position";
//设置动画的需要经过的点
CGPoint p1=CGPointZero;
CGPoint p2=CGPointMake(, );
CGPoint p3=CGPointMake(, );
CGPoint p4=CGPointMake(, );
CGPoint p5=CGPointZero; NSValue * v1=[NSValue valueWithCGPoint:p1];
NSValue * v2=[NSValue valueWithCGPoint:p2];
NSValue * v3=[NSValue valueWithCGPoint:p3];
NSValue * v4=[NSValue valueWithCGPoint:p4];
NSValue * v5=[NSValue valueWithCGPoint:p5];
//将对应的值添加到动画并且设置动画保留
keyfram.values=@[v1,v2,v3,v4,v5];
keyfram.duration=;
keyfram.fillMode=kCAFillModeForwards;
keyfram.removedOnCompletion=NO;
[_layer addAnimation:keyfram forKey:nil];
案例:通过关键帧动画实现图片摇摆
CAKeyframeAnimation * anima=[CAKeyframeAnimation animation];
//通过设置放射变换的角度来实现
anima.keyPath=@"transform.rotation";
float p1=/180.0*M_PI;
anima.duration=0.2;
anima.values=@[@(-p1),@(p1),@(-p1)];
anima.fillMode=kCAFillModeForwards;
anima.removedOnCompletion=NO;
anima.repeatCount=MAXFLOAT;
[_layer addAnimation:anima forKey:nil];
_layer.transform=CATransform3DMakeRotation(M_PI, , , );
| 三、转场动画 |
//初始化方式
CATransition * tran=[CATransition animation];
//设置动画效果
tran.type=@"rippleEffect"; //常用效果
kCATransitionFade
kCATransitionMoveIn
kCATransitionPush
kCATransitionReveal //设置动画方向
tran.subtype=kCATransitionFromLeft; //动画方向
kCATransitionFromRight
kCATransitionFromLeft
kCATransitionFromTop
kCATransitionFromBottom //设置动画保留以及动画时长
tran.fillMode=kCAFillModeForwards;
tran.removedOnCompletion=NO;
tran.duration=;
[self.myImageView.layer addAnimation:tran forKey:nil];
| 四、UIView封装动画 |
UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画支持。执行动画所需要的工作由UIView类自动完成,但仍要在希望执行动画时通知视图,为此需要将改变属性的代码放在[UIViewbeginAnimations:nil context:nil]和[UIView commitAnimations]之间
1、常见方法解析:
//设置动画代理
+ (void)setAnimationDelegate:(id)delegate //设置当动画即将开始时,执行delegate对象的selector,并且把beginAnimations:context:中传入的参数传进selector
+(void)setAnimationWillStartSelector:(SEL)selector //设置动画结束时调用方法
+ (void)setAnimationDidStopSelector:(SEL)selector //设置动画持续时间
+(void)setAnimationDuration:(NSTimeInterval)duration //设置动画延迟
+ (void)setAnimationDelay:(NSTimeInterval)delay //设置动画开始时间
+ (void)setAnimationStartDate:(NSDate *)startDate //设置动画节奏
+ (void)setAnimationCurve:(UIViewAnimationCurve)curve //设置动画重复次数
+ (void)setAnimationRepeatCount:(float)repeatCount //如果设置为YES,代表动画每次重复执行的效果会跟上一次相反
+(void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses // 设置视图view的过渡效果, transition指定过渡类型, cache设置YES代表使用视图缓存,性能较好
+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache
2、案例
//旋转动画
[UIView beginAnimations:@"roate" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:1.5];
[UIView setAnimationDelegate:self];
_view.transform=CGAffineTransformRotate(_view.transform, M_PI_2);
[UIView setAnimationDidStopSelector:@selector(endAnimate)];
[UIView commitAnimations];
//转场动画
[UIView beginAnimations:@"transition" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:_mainView cache:YES];
[UIView setAnimationDuration:1.5];
NSInteger index1=[_mainView.subviews indexOfObject:_view];
NSInteger index2=[_mainView.subviews indexOfObject:_view2];
[_mainView exchangeSubviewAtIndex:index1 withSubviewAtIndex:index2];
[UIView commitAnimations];
出处:http://www.cnblogs.com/jerehedu/
本文版权归烟台杰瑞教育科技有限公司和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
IOS中的动画——Core Animation的更多相关文章
- iOS 图形图像动画 Core Animation
//Core Animation #define WeakSelf __weak __typeof(self) weakSelf = self #define StrongSelf __strong ...
- iOS中的动画
iOS中的动画 Core Animation Core Animation是一组非常强大的动画处理API,使用它能做出非常绚丽的动画效果,而且往往是事半功倍,使用它需要添加QuartzCore .fr ...
- iOS中的动画(转载)
iOS中的动画 最近两天没事在慢慢学习一些动画,好多东西长时间不用都给忘了,找到一篇介绍很详细的文章就粘贴了过来以备复习,原文地址:https://my.oschina.net/aofe/blog/ ...
- iOS 核心动画 Core Animation浅谈
代码地址如下:http://www.demodashi.com/demo/11603.html 前记 关于实现一个iOS动画,如果简单的,我们可以直接调用UIView的代码块来实现,虽然使用UIVie ...
- (转)iOS动画Core Animation
文章转载:http://blog.sina.com.cn/s/blog_7b9d64af0101b8nh.html 在iOS中动画实现技术主要是:Core Animation. Core Animat ...
- iOS开发之核心动画(Core Animation)
1.概述 Core Animation是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍,使用它需要先添加QuartzCore.framework和引入对应的框架< ...
- IOS中的动画菜单
SvpplyTable(可折叠可张开的菜单动画) 允许你简单地创建可折叠可张开的菜单动画效果,灵感来自于Svpply app.不同表格项目使用JSON定义,你可以定义每个菜单项和任何子菜单,为每个项目 ...
- 核心动画——Core Animation
一. CALayer (一). CALayer简单介绍 在iOS中,你能看得见摸得着的东西基本上都是UIView,比方一个button.一个文本标签.一个文本输入框.一个图标等等.这些都是UIView ...
- unity从模型中抽取动画文件(animation)
http://www.cnblogs.com/leng-yuye/archive/2013/01/11/2856144.html 由于模型是由第三方的软件制作的,用unity不能直接编辑模型里的动画文 ...
随机推荐
- <泛> 多路快排
今天写一个多路快排函数模板,与STL容器兼容的. 我们默认为升序排序 因为,STL容器均为逾尾容器,所以我们这里采用的参数也是逾尾的参数 一.二路快排 基本思路 给你一个序列,先选择一个数作为基数,我 ...
- 1265. [NOIP2012] 同余方程
1265. [NOIP2012] 同余方程 ★☆ 输入文件:mod.in 输出文件:mod.out 简单对比 时间限制:1 s 内存限制:128 MB [题目描述] 求关于 x 的同余 ...
- 【MPI】并行奇偶交换排序
typedef long long __int64; #include "mpi.h" #include <cstdio> #include <algorithm ...
- Android之安全机制
根据android四大框架来解说安全机制 代码安全 java不同于C/C++,java是解释性语言,存在代码被反编译的隐患: 默认混淆器为proguard,最新版本为4.7: proguard还可用来 ...
- hdu 4536 dfs
题意:XCOM-Enemy Unknown是一款很好玩很经典的策略游戏.在游戏中,由于未知的敌人--外星人入侵,你团结了世界各大国家进行抵抗.随着游戏进展,会有很多的外星人进攻事件.每次进攻外星人会选 ...
- ZeptoLab Code Rush 2015 B. Om Nom and Dark Park DFS
B. Om Nom and Dark Park Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- TensorFlow安装和HelloWorld
TensorFlow安装 TensorFlow可以在各种操作系统上面安装.安装的时候要注意TensorFlow的类型,一种是普通的版本,仅支持CPU,安装简单.另外一种类型带GPU的,可以利用GPU来 ...
- Spotlight on linux 监控 linux服务器资源
步骤一:在window主机上安装spotlight 下载地址:http://worlddownloads.quest.com.edgesuite.net/Repository/www.quest.co ...
- PowerDesigner设置唯一约束/唯一索引/唯一键
注意:还需要设置unique约束,也是在这个界面. 参考: https://blog.csdn.net/cnham/article/details/6676650 https://blog.csdn. ...
- [Dynamic Language] pyspark Python3.7环境设置 及py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.api.python.PythonRDD.collectAndServe解决!
pyspark Python3.7环境设置 及py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spa ...