动画的组合;

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. 【10】Quartz.net 定时服务实例

    一.安装nuget包 Install-Package Quartz Install-Package Common.Logging.Log4Net1211 Install-Package log4net ...

  2. 三、hdfs的JavaAPI操作

    下文展示Java的API如何操作hdfs,在这之前你需要先安装配置好hdfs https://www.cnblogs.com/lay2017/p/9919905.html 依赖 你需要引入依赖如下 & ...

  3. [LeetCode]Generate Parentheses题解

    Generate Parentheses: Given n pairs of parentheses, write a function to generate all combinations of ...

  4. 【C++并发实战】(二)线程管理

    前一篇没用markdown编辑器感觉不好看,删了重新发 本篇主要讲述线程的管理,主要包括创建和使用线程 启动线程 线程出现是为了执行任务,线程创建时会给一个入口函数,当这个函数返回时,该线程就会退出, ...

  5. git分支无法获取

    git 上新建的分支,本地想要拉取该分支,但是找不到这个分支 使用  git branch -a  也看不到该分支 使用命令: git checkout -b branch_nameA origin/ ...

  6. apache配置域名访问本地空间

    1. 首先修改C盘WINDOWS\system32\drivers\etc目录下的 hosts 文件,用记事本打开,加入: 127.0.0.1 www.a.com hosts文件是用来解析的,你在浏览 ...

  7. Vuejs入门级简单实例

    Vue作为2016年最火的框架之一,以其轻量.易学等特点深受大家的喜爱.今天简单介绍一下Vue的使用. 首先,需要在官网下载vuejs,或者直接用cdn库.以下实例使用Vue实现数据绑定与判断循环: ...

  8. Node.js 的安装

    Node.js 是一个基于 Chrome V8 引擎的 JavaScript 的运行环境,简单的说就是运行在服务端的 JavaScript.所以学起来还是比较容易接受的. Node.js 使用事件驱动 ...

  9. Python 批量修改文件夹名称

    修改为: # -*- coding: utf-8 -*- import os, sys,re path=u"E:\\C#网络编程基础" dirs=os.listdir(path) ...

  10. Mac怎么生成.ssh文件

    可使用如下命令生成 1 ssh-keygen -t rsa 因为mac系统也是从unix基础上演变过来的,所以很多核心的东西也是与unix相通的. 1.-t 是指定加密参数为ras,默认是dsa 2. ...