Swift - CALayer的contents属性动画

效果

源码

https://github.com/YouXianMing/Swift-Animations

//
// LiveImageView.swift
// Swift-Animations
//
// Created by YouXianMing on 16/8/17.
// Copyright © 2016年 YouXianMing. All rights reserved.
// import UIKit // MARK: Public class : LiveImageView class LiveImageView: UIImageView { // MARK: Properties. /// Animation's duration.
var duration : CFTimeInterval = 0.3 // MARK: Methods. /**
Set image with animation or not. - parameter newVal: The new image.
- parameter animated: Animated or not.
*/
func setImage(newVal : UIImage, animated : Bool) { if animated == true { let animation = CABasicAnimation(keyPath: "contents")
animation.fromValue = image?.CGImage
animation.toValue = newVal.CGImage
animation.duration = duration pLayer.contents = image?.CGImage
pLayer.addAnimation(animation, forKey: nil) image = newVal } else { image = newVal
}
} // MARK: Private value & func. private var pLayer : CALayer! override init(frame: CGRect) { super.init(frame: frame)
pLayer = layer
} required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented")
}
}
//
// LiveImageViewController.swift
// Swift-Animations
//
// Created by YouXianMing on 16/8/17.
// Copyright © 2016年 YouXianMing. All rights reserved.
// import UIKit class LiveImageViewController: NormalTitleViewController { var timer : GCDTimer! = GCDTimer(inQueue: GCDQueue.mainQueue)
var count : NSInteger! =
var images : [UIImage]! = [UIImage]() override func setup() { super.setup() images = [UIImage]()
images.append(UIImage(named: "pic_1")!)
images.append(UIImage(named: "pic_2")!)
images.append(UIImage(named: "pic_3")!)
images.append(UIImage(named: "pic_4")!) let image = images[]
let liveImageView = LiveImageView(frame: CGRectMake(, , image.size.width, image.size.height))
liveImageView.center = (contentView?.middlePoint)!
liveImageView.layer.borderWidth =
liveImageView.layer.borderColor = UIColor.blackColor().CGColor
liveImageView.duration = 0.5
contentView?.addSubview(liveImageView) weak var wself = self
timer.event({ let currentIndex = (wself?.count)! % (wself?.images.count)!
wself?.count = (wself?.count)! + liveImageView.setImage(wself!.images[currentIndex], animated: true) UIView.animateWithDuration(0.5, animations: { var tmpRect = liveImageView.bounds
tmpRect.size = (liveImageView.image?.size)!
liveImageView.bounds = tmpRect
liveImageView.center = (wself?.contentView?.middlePoint)!
}) }, timeIntervalWithSeconds: 1.0) timer.start()
}
}

Swift - CALayer的contents属性动画的更多相关文章

  1. IOS开发-属性动画和关键帧动画的使用

    CAMediaTiming是一个协议(protocol),CAAnimation是所有动画类的父类,但是它不能直接使用,应该使用它的子类. 继承关系: CoreAnmiation 核心动画 简写CA ...

  2. Swift: 打造滑动解锁文字动画

    原文:Swift: 打造滑动解锁文字动画 最近木事,找出来玩了玩facebook的paper.到处都是那个"slide to unlock your phone"的效果啊.忽闪忽闪 ...

  3. iOS开发UI篇—CAlayer层的属性

    iOS开发UI篇—CAlayer层的属性 一.position和anchorPoint 1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property ...

  4. CAlayer层的属性

    iOS开发UI篇—CAlayer层的属性 一.position和anchorPoint 1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property ...

  5. iOS:CALayer的隐式动画的详解

    CALayer的隐式动画属性: •每一个UIView内部都默认关联着一个CALayer,称这个Layer为Root Layer.所有的非Root Layer都存在着隐式动画,隐式动画的默认时长为1/4 ...

  6. iOS开发UI 篇—CAlayer层的属性

    一.position和anchorPoint 1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property CGPoint position; 用来设 ...

  7. CALayer之mask属性-遮罩

    CALayer有一个属性叫做mask. 这个属性本身就是个CALayer类型,有和其他图层一样的绘制和布局属性. 它类似于一个子图层,相对于父图层(即拥有该属性的图层)布局,但是它却不是一个普通的子图 ...

  8. Additive属性动画

    Additive属性动画 参考 http://ronnqvi.st/multiple-animations/ 效果 源码 https://github.com/YouXianMing/Animatio ...

  9. [Animations] 快速上手 iOS10 属性动画

    概述 今天要说的UIViewPropertyAnimator, 是iOS10新的API 详细 代码下载:http://www.demodashi.com/demo/10639.html 基础动画, 核 ...

随机推荐

  1. 微信WeixinJSBridge的接口使用

    以下都要包含weixinApi.js(见底部git里的js文件) 1).分享 WeixinApi.ready(function(Api) { // 微信分享的数据 var wxData = { &qu ...

  2. 【LOJ】#2114. 「HNOI2015」菜肴制作

    题解 把所有边反向 从小到大枚举每个点,把每个点能到达的点挑出来,判完无解后显然是一个DAG,然后在上面求一个编号最大的拓扑序,把这些点全部标记为已选,把每次求得的拓扑序倒序输出 代码 #includ ...

  3. zookeeper命令行客户端

    前提条件:搭建好zookeeper服务器集群<Zookeeper深入认识>,并且集群成功开启. 执行zkServer.sh,客户端连接上服务器hadoop1. 都有哪些命令行操作呢?(见下 ...

  4. Centos下命令行编译MapReduce代码(Java)并打包在Hadoop中执行

    前提条件:搭建好Hadoop系统 新建文件夹:input  和  output hdfs dfs -mkdir /inputhdfs dfs -mkdir /output 查看文件系统 hdfs df ...

  5. poj-1459-最大流dinic+链式前向星-isap+bfs+stack

    title: poj-1459-最大流dinic+链式前向星-isap+bfs+stack date: 2018-11-22 20:57:54 tags: acm 刷题 categories: ACM ...

  6. 匿名方法和Lambda 表达式

    Overview 当你使用委托的时候,有时候是否会感觉到略微有些麻烦,尽管委托已经极大的减少了我们的工作量,比如,有一个方法,只需要使用一次,仅仅是传递给委托,我们就要定义一次他,这未免太 " ...

  7. INSTALL_FAILED_CONFLICTING_PROVIDER

    主要是由于调试的环境中已有一个同名的Provider存在. 解决方法是修改AndroidManifest.xml中的 <provider android:name=".apps.App ...

  8. [POJ1655]Balancing Act

    思路:DP求树的重心.对于每个结点$i$,$d_i=\displaystyle{\sum_{j\in s(i)}}d_j+1$.删去这个点能得到的最大子树大小即为$\max(\max\limits_{ ...

  9. centos7 做rails 执行rails server 报错

    做操作rails   server 时  报错 这个错误时因为一些东西没有安装 gem install execjsgem install therubyracersudo apt-get insta ...

  10. 读think in java有感

    .... 2.2.1 保存到什么地方 程序运行时,我们最好对数据保存到什么地方做到心中有数.特别要注意的是内存的分配.有六个地方都可以保存数据: (1) 寄存器.这是最快的保存区域,因为它位于和其他所 ...