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不能直接编辑模型里的动画文 ...
随机推荐
- 决策树算法(ID3)
Day Outlook Temperature Humidity Wind PlayTennis 1 Sunny Hot High Weak No 2 Sunny Hot High Strong No ...
- BZOJ3207 花神的嘲讽计划
hash值建主席树. 垃圾题面没有熟虑范围害我MLE——>RE. By:大奕哥 #include<bits/stdc++.h> #define unll unsigned long ...
- BZOJ 3956: Count 主席树 可持久化线段树 单调栈
https://www.lydsy.com/JudgeOnline/problem.php?id=3956 从描述可以得到性质: 每个好点对 ( 除了差值为1的好点对 ) 中间的数 ( i , j ) ...
- 20162325 金立清 S2 W10 C19
20162325 2017-2018-2 <程序设计与数据结构>第10周学习总结 认识 线性表和树两类数据结构,线性表中的元素是"一对一"的关系,树中的元素是" ...
- hdu 5228 枚举
题意:在前往ZJOI2015一试的路上,ZCC在同Fsygd打德州扑克时输光了所有的筹码.不过ZCC最近学会了一些黑技术.现在,他能够在游戏过程中更换任何他想要更换的牌.ZCC想要通过更换尽量少的牌得 ...
- MyBatis -- generator 逆向工程
一.引言 官网文档:http://www.mybatis.org/generator/index.html 通过使用官方提供的mapper自动生成工具,mybatis-generator-core-1 ...
- Shell 学习笔记之运算符
基本运算符 算术运算符 val = expr 2 + 2 需要注意的是 表达式和运算符之间需要有空格(比如2 + 2,不能是2+2) 两边最外面的字符是`,在esc键下面,不是引号哦 乘号* 前面必须 ...
- Remove-Invalid-Parentheses-题解
题意 Remove the minimum number of invalid parentheses in order to make the input string valid. Return ...
- Java发送HTTP POST请求示例
概述: http请求在所有的编程语言中几乎都是支持的,我们常用的两种为:GET,POST请求.一般情况下,发送一个GET请求都很简单,因为参数直接放在请求的URL上,所以,对于PHP这种语言,甚至只需 ...
- python开发_tkinter_单选菜单_不可用菜单操作
在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...