Core Animation之CABasicAnimation(基础动画)
#import "ViewController.h"
@interface ViewController ()
@property(nonatomic,strong)UIButton *btn;
@property(nonatomic,strong)CALayer *calayer;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.btn=[UIButton buttonWithType:UIButtonTypeSystem];
self.btn.frame=CGRectMake(100, 100, 100, 100);
self.btn.backgroundColor=[UIColor redColor];
[self.btn setTitle:@"按钮" forState:UIControlStateNormal];
[self.btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.btn];
}
-(void)btnClick:(id)sender
{
//基础动画两种实例化方式
// CABasicAnimation *basicAnimation=[CABasicAnimation animationWithKeyPath:@"transform"];
CABasicAnimation *basicAnimation=[CABasicAnimation animation];
//基础动画主要有三个属性 fromValue, toValue, byValue
//toValue到多少 byValue增加多少
basicAnimation.keyPath=@"position";
//这几个属性都是id类型,由于CGPoint是结构体类型,不能直接用,所以要转换一下下
// basicAnimation.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeTranslation(0, 100, 1)];
//图层transform属性是CATransform3D类型 不能用仿射变换 仿射变换是图层中的方法所以不能通过CABasicAnimation动画改变
// basicAnimation.toValue=[NSValue valueWithCGAffineTransform:CGAffineTransformMakeScale(2.0, 2.0)];
//位置变换
basicAnimation.fromValue=[NSValue valueWithCGPoint:CGPointMake(0, 0)];
basicAnimation.toValue=[NSValue valueWithCGPoint:CGPointMake(300, 300)];
//动画是添加到图层上的,动画结束后是否移除该动画 如果YES,fillMode属性基本没意义
basicAnimation.removedOnCompletion=NO;
//设置动画的状态
//kCAFillModeForwards:动画延迟结束开始执行动画时从fromValue到toValue最终停留在toValue
//kCAFillModeBackwards:动画在fromValue后开始延迟,延迟结束执行动画,从fromValue到toValue,最终到初始值状态
//kCAFillModeBoth:动画在fromValue后开始延迟,延迟结束执行动画,从fromValue到toValue,最终到toValue
//kCAFillModeRemoved:动画延迟结束开始执行动画时从fromValue到toValue最终停留在初始值状态
basicAnimation.fillMode=kCAFillModeRemoved;
//动画共有的一些属性
basicAnimation.duration=5.0;
// 延迟5秒执行
basicAnimation.beginTime=CACurrentMediaTime()+5;
//设置动画的代理
basicAnimation.delegate=self;
//在图层中增加动画
[self.btn.layer addAnimation:basicAnimation forKey:nil];
}
//CAAnimation动画代理方法 这两个代理方法是在CAAnimation中的代理,所以其他的动画也可以使用
- (void)animationDidStart:(CAAnimation *)anim
{
NSLog(@"动画开始");
}
//CAAnimation动画代理方法结束动画
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
NSLog(@"动画结束");
NSLog(@"%f",self.btn.frame.origin.x);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end

Core Animation之CABasicAnimation(基础动画)的更多相关文章
- Core Animation中的基础动画
基础动画 在开发过程中很多情况下通过基础动画就可以满足开发需求,前面例子中使用的UIView代码块进行图像放大缩小的演示动画也是基础动画(在iOS7 中UIView也对关键帧动画进行了封装),只是UI ...
- Core Animation之CABasicAnimation
在iOS中,图形可分为以下几个层次: 越上层,封装程度越高,动画实现越简洁越简单,但是自由度越低:反之亦然.本文着重介绍Core Animation层的基本动画实现方案. 在iOS中,展示动画可以类比 ...
- 使用Core Animation对象来实现动画
转载保留原文地址:http://blog.csdn.net/kqjob/article/details/10417461,转载的 在iOS中如果使用普通的动画则可以使用UIKit提供的动画方式来实现, ...
- iOS Core Animation学习总结(3)--动画的基本类型
一. CABasicAnimation (基础动画) 移位: CABasicAnimation *animation = [CABasicAnimation animation]; //keyPath ...
- Core Animation中的组动画
实际开发中一个物体的运动往往是复合运动,单一属性的运动情况比较少,但恰恰属性动画每次进行动画设置时一次只能设置一个属性进行动画控制(不管是 基础动画还是关键帧动画都是如此),这样一来要做一个复合运动的 ...
- core Animation之CAKeyframeAnimation(关键帧动画)
CABasicAnimation的区别是:CABasicAnimation只能从一个数值(fromValue)变到另一个数值(toValue),而CAKeyframeAnimation会使用一个NSA ...
- 在ios中运用core animation暂停和继续动画
本文转载至 http://blog.csdn.net/wildfireli/article/details/23191861 暂停和继续动画的核心代码如下: <pre name="co ...
- Core Animation中的关键帧动画
键帧动画就是在动画控制过程中开发者指定主要的动画状态,至于各个状态间动画如何进行则由系统自动运算补充(每两个关键帧之间系统形成的动画称为“补间动画”),这种动画的好处就是开发者不用逐个控制每个动画帧, ...
- Core Animation一些Demo总结 (动态切换图片、大转盘、图片折叠、进度条等动画效果)
前一篇总结了Core Animation的一些基础知识,这一篇主要是Core Animation 的一些应用,涉及到CAShapeLayer.CAReplicatorLayer等图层的知识. 先看效果 ...
随机推荐
- E - Evaluate Matrix Sum
Description Given a matrix, the elements of which are all integer number from 0 to 50, you are requi ...
- OmniThreadLibrary学习笔记
http://blog.sina.com.cn/s/articlelist_1157240623_6_1.html 非常好的控件,仔细看
- Java map的匿名类的初始化
可以直接使用: Map<String, Object> testMap = new HashMap<String, Object>() { { put("test1& ...
- Maximum repetition substring(POJ - 3693)(sa(后缀数组)+st表)
The repetition number of a string is defined as the maximum number \(R\) such that the string can be ...
- 协程 coroutine
参考链接: http://manual.luaer.cn/2.11.html http://www.cnblogs.com/riceball/archive/2008/01/03/1025158.ht ...
- abstract抽象
abstract:抽象 是用来修饰抽象类和抽象方法的 那么什么抽象,抽象有究竟有什么用呢?? 我们知道,“类”是某一类具有相同特征或行为的物事,是将这些物事特征向上抽取得来的:“父类”也是子类不断向上 ...
- Spring boot mybatis : Error creating bean with name 'com.github.pagehelper.autoconfigure.MapperAutoConfiguration': Invocation of init method failed;
报错截图: 解决方法: 只能扫描到自定义的mapper,不能扫描到其他文件. @MapperScan("com.streamax.s17.tms.dao.pper.repository&qu ...
- C++类和对象(一)&&实现offsetof宏&&this指针
一.目录 1.对象的相关知识 2.类的定义 3.类的实例化 4.类对象模型 5.模拟实现offsetof宏 6.this指针 二.正文 1.对象的相关知识 C语言是面向过程的,关注的是过程,分析求解问 ...
- Ubuntu 12.04 安装Redis并设置主从复制
今天想在Ubuntu上安装一个Redis服务器并配置Master-Slave,一开始懒得连VPN就查了一些国内的文章,不知道是没有亲自验证过的转载文章,还是版本问题造成的,发现按照步骤都没能成功完成配 ...
- docker学习实践之路[第五站]mysql镜像应用
拉取mysql镜像 docker pull mysql:5.6 #拉取mysql .6版本的镜像 运行mysql镜像 docker run --name some-mysql --restart=al ...