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 基础动画, 核 ...
随机推荐
- java 异常匹配
抛出异常的时候,异常处理系统会安装代码书写顺序找出"最近"的处理程序. 找到匹配的程序后,它就认为异常将得到清理,然后就不再继续查找. 查找的时候并不要求抛出的异常同处理程序的异常 ...
- MVC母板页传递数据
问题:判断Session 失败 结果: if (Session[SessionKey.AccountInfo] != null) { ViewData["AdminUser"] = ...
- open-falcon v0.2 监控部署记录
前言 好吧,不知道为什么要写,其实,官方文档已经很详细.但是,总是想写点什么,怕自己忘记了.那就简单说说吧,在部署过程中,发现官方文档和我想的不一样,可能是我按照顺序习惯了,所以想从新跟着顺写来记录一 ...
- 洛谷P2261 [CQOI2007] 余数求和 [数论分块]
题目传送门 余数求和 题目背景 数学题,无背景 题目描述 给出正整数n和k,计算G(n, k)=k mod 1 + k mod 2 + k mod 3 + … + k mod n的值,其中k mod ...
- python3之Django模型(一)
1.模型概述 模型是关于您的数据的唯一,明确的信息来源,它包含您正在存储的数据的重要字段和行为.通常,每个模型映射到单个数据库表. 每个模型都是一个子类的python类django.db.models ...
- Oracle的一些初步小东西
经常要用数据库,让他自己启动的话,开机太慢,所以用命令启动方便点. 1.开启: 在运行中输入cmd,进入控制台,lsnrctl start回车,提示启动监听成功后net start Oracl ...
- ARP协议详解之Gratuitous ARP(免费ARP)
ARP协议详解之Gratuitous ARP(免费ARP) Gratuitous ARP(免费ARP) Gratuitous ARP也称为免费ARP,无故ARP.Gratuitous ARP不同于一般 ...
- 数据转换bug花了半天时间 Java.math.BigDecimal cannot be cast to java.lang.String
从数据库取出一个 Count函数 统计的值 在代码中要转成Integer类型的时候 Integer.parseInt((String)map.get("ID_")) 报了一下错误: ...
- 吴恩达-coursera-机器学习-week7
十二.支持向量机(Support Vector Machines) 12.1 优化目标 12.2 大边界的直观理解 12.3 数学背后的大边界分类(选修) 12.4 核函数1 12.5 核函数2 12 ...
- MySQL_事务没有提交导致 锁等待 Lock wait timeout exceeded
java.lang.Exception:### Error updating database. Cause: java.sql.SQLException: Lock wait timeout ex ...