Swift - CALayer的contents属性动画
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属性动画的更多相关文章
- IOS开发-属性动画和关键帧动画的使用
CAMediaTiming是一个协议(protocol),CAAnimation是所有动画类的父类,但是它不能直接使用,应该使用它的子类. 继承关系: CoreAnmiation 核心动画 简写CA ...
- Swift: 打造滑动解锁文字动画
原文:Swift: 打造滑动解锁文字动画 最近木事,找出来玩了玩facebook的paper.到处都是那个"slide to unlock your phone"的效果啊.忽闪忽闪 ...
- iOS开发UI篇—CAlayer层的属性
iOS开发UI篇—CAlayer层的属性 一.position和anchorPoint 1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property ...
- CAlayer层的属性
iOS开发UI篇—CAlayer层的属性 一.position和anchorPoint 1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property ...
- iOS:CALayer的隐式动画的详解
CALayer的隐式动画属性: •每一个UIView内部都默认关联着一个CALayer,称这个Layer为Root Layer.所有的非Root Layer都存在着隐式动画,隐式动画的默认时长为1/4 ...
- iOS开发UI 篇—CAlayer层的属性
一.position和anchorPoint 1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property CGPoint position; 用来设 ...
- CALayer之mask属性-遮罩
CALayer有一个属性叫做mask. 这个属性本身就是个CALayer类型,有和其他图层一样的绘制和布局属性. 它类似于一个子图层,相对于父图层(即拥有该属性的图层)布局,但是它却不是一个普通的子图 ...
- Additive属性动画
Additive属性动画 参考 http://ronnqvi.st/multiple-animations/ 效果 源码 https://github.com/YouXianMing/Animatio ...
- [Animations] 快速上手 iOS10 属性动画
概述 今天要说的UIViewPropertyAnimator, 是iOS10新的API 详细 代码下载:http://www.demodashi.com/demo/10639.html 基础动画, 核 ...
随机推荐
- [转]解决阿里云mysql不能连接,配置mysql远程连接
默认是不能用客户端远程连接的,阿里云提供的help.docx里面做了设置说明,mysql密码默认存放在/alidata/account.log 首先登录: mysql -u root -h local ...
- ***实用函数:PHP explode()函数用法、切分字符串,作用,将字符串打散成数组
下面是根据explode()函数写的切分分割字符串的php函数,主要php按开始和结束截取中间数据,很实用 代码如下: <? // ### 切分字符串 #### function jb51net ...
- **CI创建类库(创建自己的工具类等)
创建类库 当我们使用术语"类库"时,我们一般指的是位于libraries 文件夹中的类,它们在wiki的"类库参考"这个板块被讨论.在当前这个话题中,我们将讨论 ...
- .NetCore下使用Prometheus实现系统监控和警报 (三)集成Grafana
有了前面InfluxDB的经验,这里就很好处理了,数据类型选择Prometheus选地址等,填好保存 同样通过导入数据处理,我们在https://grafana.com/dashboards上选择Da ...
- 【PAT】1020 Tree Traversals (25)(25 分)
1020 Tree Traversals (25)(25 分) Suppose that all the keys in a binary tree are distinct positive int ...
- 【LOJ】 #2308. 「APIO2017」商旅
题解 分数题可以想到分数规划,我们预处理出从i到j卖什么货物赚的最多,然后把每条边的边权改成"利润 - 效率 × 时间" 用spfa找正环即可 代码 #include <bi ...
- 1195: [HNOI2006]最短母串
思路:好像以前谁问过我这题... 状个压就好啦, 把包含在其他串中的字符串删掉, 预处理除每两个字符串之间的关系, dp[ state ][ i ] 表示在state的状态下, 最后一个字符串是第i ...
- 028 Partitioner:数据分区器
Partitioner:数据分区器,决定数据到下一个RDD的时候在那一个分区 HashPartitioner:根据key的hashCode值来实现 RangePartitioner: 根据key所属范 ...
- 附001.etcd配置文件详解
一 示例yml配置文件 # This is the configuration file for the etcd server. # Human-readable name for this m ...
- 堆排序之Java实现
堆排序之Java实现 代码: package cn.com.zfc.lesson21.sort; /** * * @title HeapSort * @describe 堆排序 * @author 张 ...