动画的组合;

caanimationgroup:同一个layer;

CATransaction:不同layer;

In Core Animation, transactions are a way to group multiple animation-related changes together. Transactions ensure that the desired animation changes are committed to Core Animation at the same time:

CATransaction.begin()

backingLayer1.opacity = 1.0
backingLayer2.position = CGPoint(x: 50.0, y: 50.0)
backingLayer3.backgroundColor = UIColor.red.cgColor CATransaction.commit()

UIView itself has a handful of functions involved with enabling and disabling animations, such as setAnimationsEnabled(_:) and performWithoutAnimation(_:). However, to ensure that both UIView-style and CALayer-style animations are suppressed, you can always just use CATransaction.

https://www.calayer.com

CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

rotationAnimation.toValue = [NSNumber numberWithFloat:(2 * M_PI) * 2];

rotationAnimation.duration = 1;

rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];

scaleAnimation.toValue = [NSNumber numberWithFloat:0.0];

scaleAnimation.duration = 1;

scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

CAAnimationGroup *animationGroup = [CAAnimationGroup animation];

animationGroup.duration = 1;

animationGroup.autoreverses = YES;

animationGroup.repeatCount = 1;

animationGroup.animations =[NSArray arrayWithObjects:rotationAnimation, scaleAnimation, nil];

[view.layer addAnimation:animationGroup forKey:@"animationGroup"];

CATransaction.begin()

CATransaction.setAnimationDuration(1.0)

CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut))

// Layer animation

let myAnimation = CABasicAnimation(keyPath: "frame");

myAnimation.toValue = NSValue(cgRect: myNewFrame)

myAnimation.fromValue = NSValue(cgRect: myLayer.frame)

myLayer.frame = myNewFrame

myLayer.add(myAnimation, forKey: "someKeyForMyAnimation")

// Outer animation

let outerAnimation = CABasicAnimation(keyPath: "frame")

outerAnimation.toValue = NSValue(cgRect: myNewOuterFrame)

outerAnimation.fromValue = NSValue(cgRect: outerView.frame)

outerView.layer.frame = myNewOuterFrame

outerView.layer.add(outerAnimation, forKey: "someKeyForMyOuterAnimation")

CATransaction.commit()

//保证 insert row 不闪屏

UIView.setAnimationsEnabled(false)

CATransaction.begin()

CATransaction.setDisableActions(true)

self.beginUpdates()

self.insertRows(at: rows, with: .none)

self.endUpdates()

self.scrollToRow(at: rows[0], at: .bottom, animated: false)

CATransaction.commit()

UIView.setAnimationsEnabled(true)

caanimationgroup与CATransaction的区别的更多相关文章

  1. iOS 用CALayer实现动画

    与动画有关的几个类的继承关系 涉及到动画的类主要有6个,看一下它们的基本用途: 1. CAAnimation  动画基类 2. CAAnimationGroup 组合多个动画 3. CAPropert ...

  2. CoreAnimation confusion: CATransaction vs CATransition vs CAAnimationGroup?

    http://stackoverflow.com/questions/14042755/coreanimation-confusion-catransaction-vs-catransition-vs ...

  3. c#与java的区别

    经常有人问这种问题,用了些时间java之后,发现这俩玩意除了一小部分壳子长的还有能稍微凑合上,基本上没什么相似之处,可以说也就是马甲层面上的相似吧,还是比较短的马甲... 一般C#多用于业务系统的开发 ...

  4. jquery和Js的区别和基础操作

    jqery的语法和js的语法一样,算是把js升级了一下,这两种语法可以一起使用,只不过是用jqery更加方便 一个页面想要使用jqery的话,先要引入一下jqery包,jqery包从网上下一个就可以, ...

  5. 【原】nodejs全局安装和本地安装的区别

    来微信支付有2年多了,从2年前的互联网模式转变为O2O模式,主要的场景是跟线下的商户去打交道,不像以往的互联网模式,有产品经理提需求,我们帮忙去解决问题. 转型后是这样的,团队成员更多需要去寻找业务的 ...

  6. 探究@property申明对象属性时copy与strong的区别

    一.问题来源 一直没有搞清楚NSString.NSArray.NSDictionary--属性描述关键字copy和strong的区别,看别人的项目中属性定义有的用copy,有的用strong.自己在开 ...

  7. X86和X86_64和X64有什么区别?

    x86是指intel的开发的一种32位指令集,从386开始时代开始的,一直沿用至今,是一种cisc指令集,所有intel早期的cpu,amd早期的cpu都支持这种指令集,ntel官方文档里面称为&qu ...

  8. Java中Comparable与Comparator的区别

    相同 Comparable和Comparator都是用来实现对象的比较.排序 要想对象比较.排序,都需要实现Comparable或Comparator接口 Comparable和Comparator都 ...

  9. MySQL中interactive_timeout和wait_timeout的区别

    在用mysql客户端对数据库进行操作时,打开终端窗口,如果一段时间没有操作,再次操作时,常常会报如下错误: ERROR (HY000): Lost connection to MySQL server ...

随机推荐

  1. nodejs使用sequelize操作mysql实例

    sequelize是node操作mysql的一款npm包,包含很多特性:数据库模型映射.事务处理.模型属性校验.关联映射等,花了两天时间学习了下基本的一些操作,特别是关联映射部分的操作,包含1:1.1 ...

  2. Spring Boot学习笔记(三)实现热部署

    pom文件中添加如下依赖即可 <dependency> <groupId>org.springframework.boot</groupId> <artifa ...

  3. 转:zip 和 unzip 的参数说明

    收集的资料: 1. 我想把一个文件abc.txt和一个目录dir1压缩成为yasuo.zip: # zip -r yasuo.zip abc.txt dir1 2.我下载了一个yasuo.zip文件, ...

  4. 基于.Net下整合IBatis

    一. 准备工作 1. 点击此下载支持.Net4.0的 iBatis.Net,工程中引用release文件夹下的dll 最新版(目前已不再更新),有稍作修改使其支持.NET4.0 2. 点击此可查看 i ...

  5. K:括号分隔符匹配问题

    相关介绍:  括号分隔符匹配问题是指,判断所输入的字符串表达式中的括号是否匹配的问题,例如1+(12+2)*(1+2)便是一个括号分隔符匹配的表达式,而(12+1)*4+(12/2]就是一个括号分隔符 ...

  6. RequireJS 是一个JavaScript模块加载器

    RequireJS 是一个JavaScript模块加载器.它非常适合在浏览器中使用, 它非常适合在浏览器中使用,但它也可以用在其他脚本环境, 就像 Rhino and Node. 使用RequireJ ...

  7. Swift Development – List of Resources You Must Bookmark

    Ever since the introduction of iOS, there is iOS development fever across the globe. Many iOS develo ...

  8. drupal7 profile2模块获取个人信息

    一.问题背景: 用profile2模块,扩展个人信息,增加了“手机号”等信息,一些地方想要获取当前用户的手机号 二.解决办法: 用profile2自带的方法:profile2_load_by_user ...

  9. 获取JPEGImageEncoder和JPEGCode这两个类

    最近要对PDF做一些操作,在查看别人代码,拿过来借用的时候,由于代码不完整,引用的类也不全,导致JPEGImageEncoder和JPEGCode这两个类找不到,后来网上搜索了下,发现这两个类来自于J ...

  10. Integer 和 int 值比较

    int 是基本数据类型,会进池,可以使用 == 判断两个值相等 Integer是对象,比较对象不能使用 == , 可以使用Integer.intValue()将取出对象值比较