ios开发之核心动画四:核心动画-Core Animation--CABasicAnimation基础核心动画




#import "ViewController.h" @interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *redView; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. } -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { //1.创建动画对象(设置layer的属性值.)
CABasicAnimation *anim = [CABasicAnimation animation];
//2.设置属性值
anim.keyPath = @"position.x";
anim.toValue = @; //动画完成时, 会自动删除动画
anim.removedOnCompletion = NO;
anim.fillMode = @"forwards"; //3.添加动画:key值是为了区分不同的动画
[self.redView.layer addAnimation:anim forKey:nil]; }
核心动画之作用在层上面.
动画的本质是改图层的某一个属性.
CABasicAnimation *anim = [CABasicAnimation animation];
图层有那些属性,这里才能写那些属性.
anim.keyPath = @"transform.scale";
anim.toValue = @0.5;
告诉动画完成的时候不要移除
anim.removedOnCompletion = NO;
保存动画最前面的效果.也就是最后一个设置的效果
anim.fillMode = kCAFillModeForwards;
把动画添加到层上面.
[_redView.layer addAnimation:anim forKey:nil];
二:心跳效果
#import "ViewController.h" @interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageV; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
} -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { //创建动画对象
CABasicAnimation *anim = [CABasicAnimation animation]; //设置属性值
anim.keyPath = @"transform.scale";
anim.toValue = @; //设置动画执行次数
anim.repeatCount = MAXFLOAT; //设置动画执行时长
anim.duration = ; //自动反转(怎么样去 怎么样回来)
anim.autoreverses = YES; //添加动画
[self.imageV.layer addAnimation:anim forKey:nil]; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
思路:就是让一张图片做一个放大缩放小的动画.
代码实现:
CABasicAnimation *anim =[CABasicAnimation animation];
设置缩放属性
anim.keyPath = @"transform.scale";
缩放到最小
anim.toValue = @0;
设置动画执行的次数
anim.repeatCount = MAXFLOAT;
设置动画执行的时长
anim.duration = 0.25;
设置动画自动反转(怎么去, 怎么回)
anim.autoreverses = YES;
添加动画
[self.heartView.layer addAnimation:anim forKey:nil];
ios开发之核心动画四:核心动画-Core Animation--CABasicAnimation基础核心动画的更多相关文章
- iOS 核心动画 Core Animation浅谈
代码地址如下:http://www.demodashi.com/demo/11603.html 前记 关于实现一个iOS动画,如果简单的,我们可以直接调用UIView的代码块来实现,虽然使用UIVie ...
- 使用Core Animation对象来实现动画
转载保留原文地址:http://blog.csdn.net/kqjob/article/details/10417461,转载的 在iOS中如果使用普通的动画则可以使用UIKit提供的动画方式来实现, ...
- iOS开发之核心动画(Core Animation)
1.概述 Core Animation是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍,使用它需要先添加QuartzCore.framework和引入对应的框架< ...
- iOS开发笔记7:Text、UI交互细节、两个动画效果等
Text主要总结UILabel.UITextField.UITextView.UIMenuController以及UIWebView/WKWebView相关的一些问题. UI细节主要总结界面交互开发中 ...
- 核心动画——Core Animation
一. CALayer (一). CALayer简单介绍 在iOS中,你能看得见摸得着的东西基本上都是UIView,比方一个button.一个文本标签.一个文本输入框.一个图标等等.这些都是UIView ...
- (转)iOS动画Core Animation
文章转载:http://blog.sina.com.cn/s/blog_7b9d64af0101b8nh.html 在iOS中动画实现技术主要是:Core Animation. Core Animat ...
- CABasicAnimation基础核心动画
核心动画之作用在层上面. 动画的本质是改图层的某一个属性. CABasicAnimation *anim = [CABasicAnimation animation]; 图层有 ...
- iOS Core Animation学习总结(3)--动画的基本类型
一. CABasicAnimation (基础动画) 移位: CABasicAnimation *animation = [CABasicAnimation animation]; //keyPath ...
- IOS中的动画——Core Animation
一.基础动画 CABasicAnimation //初始化方式 CABasicAnimation * cabase=[CABasicAnimation animation]; //通过keyPath设 ...
随机推荐
- 利用JAVA反射机制实现调用私有方法
1.fragment是AccessibilityFragment的對象.须要被調用的方法的類. setAccessible(true)并非将方法的訪问权限改成了public.而是取消java的权限控制 ...
- [NowCoder]牛客网NOIP赛前集训营-提高组(第六场)题解
A.最长路 题意:给定有向图,每条边有个字符\([0,10^9]\),求每个点最长路字典序最小的方案.\(N,M\le 10^6\) 建反图跑拓扑排序,显然入过队的点都有最长路,考虑如何判断字典序大小 ...
- 1.18 Python基础知识 - Python内置函数
官方地址:https://docs.python.org/3.5/library/functions.html abs(x): 返回数字的绝对值 all(iterable): 如果迭代器的所有元素都为 ...
- ByteUtils
package sort.bing.com; import java.io.ByteArrayOutputStream;import java.io.DataOutputStream;import j ...
- ORA-00957: 反复的列名
1.错误描写叙述 ORA-00957: 反复的列名 2.错误原因 SQL> create table info( 2 stu_id varchar2(7) not null, 3 stu_nam ...
- 1.1 Introduction中 Putting the Pieces Together官网剖析(博主推荐)
不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Putting the Pieces Together 拼在一起 This comb ...
- golang encoding/json
package main import ( "bytes" "encoding/json" "fmt" ) type ColorGroup ...
- 将一个字符串当做一个方法名或对象的key
var func = "test" // 方法 [func](){ console.log("test===>") } //调用 test() //打印 ...
- 【例题 7-9 UVA-1601】The Morning after Halloween
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 对于没有出现的,当成0节点就好. 所以总是认为有3个人需要走到各自的终点. 将平面图转成点边图.这样比较好枚举. (二维变成一维,模 ...
- ajax上传进度条
<script type="text/javascript"> function register(){ var frm = document.getElementBy ...