Swift - 多个mask的动画效果

效果

源码

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

//
// TranformFadeView.swift
// Swift-Animations
//
// Created by YouXianMing on 16/8/20.
// Copyright © 2016年 YouXianMing. All rights reserved.
// import UIKit enum TranformFadeViewAnimatedType : Int { case Fade, Show
} // MARK: TranformFadeView class TranformFadeView: UIView { // MARK: Convenience init. convenience init(frame: CGRect, verticalCount : Int, horizontalCount : Int, fadeDuradtion : NSTimeInterval, animationGapDuration : NSTimeInterval) { self.init(frame: frame)
self.verticalCount = verticalCount
self.horizontalCount = horizontalCount
self.fadeDuradtion = fadeDuradtion
self.animationGapDuration = animationGapDuration
self.makeConfigEffective()
} // MARK: Properies & funcs. /// The content imageView's image.
var image : UIImage? { get { return imageView.image}
set(newVal) { imageView.image = newVal}
} /// The content imageView's contentMode.
var imageContentMode: UIViewContentMode { get { return imageView.contentMode}
set(newVal) { imageView.contentMode = newVal}
} /// Vertical direction view's count.
var verticalCount : Int! /// Horizontal direction view's count.
var horizontalCount : Int! /// One of the maskView's animation duration, default is 1.0
var fadeDuradtion : NSTimeInterval! = /// The animation duration two subViews from allMaskView, default is 0.2
var animationGapDuration : NSTimeInterval! = 0.2 /**
Make the config effective.
*/
func makeConfigEffective() { if verticalCount < || horizontalCount < { return;
} if allMaskView != nil { allMaskView.removeFromSuperview()
} countNumArray.removeAll() allMaskView = UIView(frame: bounds)
maskView = allMaskView let height = bounds.size.height
let width = bounds.size.width
let maskViewHeight = height / CGFloat(verticalCount)
let maskViewWidth = width / CGFloat(horizontalCount) var count : Int =
for horizontal in ..< horizontalCount { for vertical in ..< verticalCount { let frame = CGRectMake(maskViewWidth * CGFloat(horizontal), maskViewHeight * CGFloat(vertical), maskViewWidth, maskViewHeight)
let maskView = UIView(frame: frame)
maskView.tag = maskViewTag + count
maskView.backgroundColor = UIColor.blackColor()
allMaskView.addSubview(maskView) count = count + ;
}
} maskViewCount = count for i in ..< maskViewCount { countNumArray.append(i)
}
} /**
Start transform to fade or show state. - parameter animated: Animated or not.
- parameter transformTo: Show or fade.
*/
func start(animated animated : Bool, transformTo : TranformFadeViewAnimatedType) { if animated == true { let tmpFadeDuradtion = fadeDuradtion < ? 1.0 : fadeDuradtion
let tmpGapDuration = animationGapDuration < ? 0.2 : animationGapDuration for i in ..< maskViewCount { let tmpView = allMaskView.viewWithTag(maskViewTag + i) UIView.animateWithDuration(tmpFadeDuradtion, delay: NSTimeInterval(i) * tmpGapDuration, options: .CurveLinear, animations: { switch transformTo { case .Fade :
tmpView?.alpha = 0.0 case .Show :
tmpView?.alpha = 1.0
} }, completion: nil)
} } else { for i in ..< maskViewCount { let tmpView = allMaskView.viewWithTag(maskViewTag + i) switch transformTo { case .Fade :
tmpView?.alpha = 0.0 case .Show :
tmpView?.alpha = 1.0
}
}
}
} // MARK: System methods & Private properties private var imageView : UIImageView!
private var allMaskView : UIView!
private var maskViewCount : Int!
private var countNumArray : [Int]!
private var maskViewTag : Int = override init(frame: CGRect) { super.init(frame: frame) imageView = UIImageView(frame: bounds)
imageView.layer.masksToBounds = true
countNumArray = [Int]()
self.addSubview(imageView)
} required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented")
}
}

Swift - 多个mask的动画效果的更多相关文章

  1. Swift - 用UIScrollView实现视差动画效果

    Swift - 用UIScrollView实现视差动画效果 效果 源码 https://github.com/YouXianMing/Swift-Animations // // MoreInfoVi ...

  2. Swift - 使用atlas图集实现动画效果(SpriteKit游戏开发)

    我们通常继承SKSpriteNode来实现游戏中的元素,除了可以使用图片作为纹理皮肤外.我们还可以使用动画纹理集来实现动画播放. 动画纹理集的制作也很简单,首先要有一套动画序列图,然后把它们放到一个文 ...

  3. Swift 添加到TableView实现动画效果

    let indexPath = NSIndexPath(forRow:0 ,inSection:0) self.tableView.insertRowsAtIndexPaths([indexPath] ...

  4. Swift - CALayer的contents属性动画

    Swift - CALayer的contents属性动画 效果 源码 https://github.com/YouXianMing/Swift-Animations // // LiveImageVi ...

  5. iOS开发——动画篇Swift篇&动画效果的实现

    Swift - 动画效果的实现   在iOS中,实现动画有两种方法.一个是统一的animateWithDuration,另一个是组合出现的beginAnimations和commitAnimation ...

  6. Swift - 使用CABasicAnimation实现动画效果

    1,CABasicAnimation类只有三个属性: fromValue:开始值 toValue:结束值 Duration:动画的时间 2,通过animationWithKeyPath键值对的方式设置 ...

  7. [Swift通天遁地]五、高级扩展-(11)图像加载Loading动画效果的自定义和缓存

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  8. Swift 带有动画效果的TabBarItem

    额...貌似挺长时间没有总结新知识了,最近在看swift,之前swift刚出来的时候大体看了一遍,后来时间长了没看加之swift2.0做了比较大的调整,公司项目也不是用swift写的,也就没怎么看了, ...

  9. Swift - 动画效果的实现方法总结(附样例)

    在iOS中,实现动画有两种方法.一个是统一的animateWithDuration,另一个是组合出现的beginAnimations和commitAnimations.这三个方法都是类方法. 一,使用 ...

随机推荐

  1. ruby语言学习笔记2

    ruby学习笔记2  (摘自<ruby程序设计语言教程(中文版)>.pdf,全书25页) 1.同一个问题ruby有多个解决方案,途径 ruby之父:松本行弘(Matz),1993年创立 r ...

  2. ****timeago.js插件:jquery实现几分钟前、几小时前、几天前等时间差显示效果的代码实例

    前端 时间个性化 插件 jquery.timeago.js 关键词 : 时间格式化 刚刚 N分钟前 N小时前 N天前 N月前 N年前 MM-dd hh:mm  或者  yyyy-MM-dd 前端: & ...

  3. CI框架中自带的加密解密如何应用

    首先我们找到配置文件application/config/config.php  ,找到如下代码: ? 1 $config['encryption_key'] = "YOUR KEY&quo ...

  4. AndroidManifest.xml中android:configChanges的简介

    程序在运行时,一些设备的配置可能会改变,如:横竖屏的切换.键盘的可用性等,这样的事情一发生,Activity会重新启动,其中的过程是:在销毁之前会先 called onSaveInstanceStat ...

  5. zoj 3827(2014牡丹江现场赛 I题 )

    套公式 Sample Input 33 bit25 25 50 //百分数7 nat1 2 4 8 16 32 3710 dit10 10 10 10 10 10 10 10 10 10Sample ...

  6. React 中 context 的使用

    官方文档说明(英) 看了别人写的中文博客,再看了官方英文文档,发现还是官方文档讲的浅显易懂一些,看了之后,半翻译半理解地写了这篇博客,更易于新手理解. 介绍 context 是在 react @ 0. ...

  7. select 详解

    In summary, a socket will be identified in a particular set when select returns if: readfds:If liste ...

  8. python selenium-webdriver 环境搭建(一)

    selenium 虽然过了这么多年,但是到目前为止依然是比较流行的自动化框架了,还有很多的初学者在学习,所以根据自己的时间将把相关的资料汇总一下,下面首先我们需要搭建一下基础环境. 首先自己本身比较笨 ...

  9. js冲刺一下

    js中__proto__和prototype的区别和关系 1.对象有属性__proto__,指向该对象的构造函数的原型对象. 2.方法除了有属性__proto__,还有属性prototype,prot ...

  10. rsync基础

    参考资料:骏马金龙的rsync系列.该博主的博文质量很好,推荐大家关注. 环境 操作系统:CentOS Linux release 7.5.1804 (Core) 软件:rsync  version ...