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. vim 如何与外界粘贴复制

    在学习使用vim 的过程序,我们知道在vim 里面,粘贴复制的命令是y/p ,但是我们总会碰到这样的问题:如何把vim 里面复制的内容粘贴到vim 之外或者把vim 外面复制的内容粘贴到vim 里面? ...

  2. Kotlin中var和val的区别

    Kotlin中有两个关键字定义变量,这两个关键字外形看着差别很小就只差了一个字母,但实际差别很大的. var是一个可变变量,这是一个可以通过重新分配来更改为另一个值的变量.这种声明变量的方式和Java ...

  3. Codeforces 405E Graph Cutting

    Graph Cutting 不会写.. dfs的过程中把回边丢到它的祖先中去, 回溯的时候两两配对.感觉好神奇啊. #include<bits/stdc++.h> #define LL l ...

  4. html (第四本书第七章浮动参考)

    课上1 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8 ...

  5. Linux学习路线+资源

    Linux学习路线,个人收集分享 学习路线图 资源链接(蓝色下划线字体对应相应资源链接) Linux 基础 Linux 基础 Linux安装专题教程 Linux中文环境 Linux—从菜鸟到高手 鸟哥 ...

  6. vue 直接改变数组数据不刷新

    因为 JavaScript 的限制,Vue.js 不能检测到下面数组变化: 直接用索引设置元素,如 vm.items[0] = {}: 修改数据的长度,如 vm.items.length = 0. 为 ...

  7. Spring_之注解事务 @Transactional

    spring 事务注解 默认遇到throw new RuntimeException("...");会回滚需要捕获的throw new Exception("...&qu ...

  8. 解决Android LogCat 输出乱码的问题(转)

    Android日志系统提供了记录和查看系统调试信息的功能.日志都是从各种软件和一些系统的缓冲区中记录下来的. 可以使用adb的logcat 命令来查看系统日志缓冲区的内容,但是在实际操作时,会发现在C ...

  9. How to detect the types of executable files

    How to detect the types of executable files type { IMAGE_DOS_HEADER: DOS .EXE header. } IMAGE_DOS_HE ...

  10. JAVA GC 图解

    http://www.cnblogs.com/hnrainll/archive/2013/11/06/3410042.html http://www.blogjava.net/ldwblog/arch ...