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. js里size和length的区别

    length: length是js的原生方法,用于获取元素的个数和对象的长度 var length = $(obj).length; size(): size()属于方法,只能作用于对象上,获取元素的 ...

  2. 前端Datatables自定义事件(监听Datatables插件一些常见的事件动作)

    今天开发项目的时候,用Datatables插件做前端分页列表,想在列表发生翻页.排序.搜索.改变单页显示数据条数这些行为的时候做一些其他的操作,看了半天Datatables官网终于找到可以监测到这些事 ...

  3. kaldi 三个脚本cmd.sh path.sh run.sh

    参考   kaldi 的全部资料_v0.4 cmd.sh 脚本为: 可以很清楚的看到有 3 个分类分别对应 a,b,c.a 和 b 都是集群上去运行这个样子, c 就是我们需要的.我们在虚拟机上运行的 ...

  4. NFS配置及开机自动挂载

    环境:Red Hat  6.7 服务端:192.168.163.128 客户端:192.168.163.131 背景:解决多个服务器之间数据共享 环境检查: 1.检查服务器是否安装nfs服务 rpm  ...

  5. win10无线网连接 提示无法连接到此网络

    一.Win10无法连接此网络是怎么回事 对于大多数遇到无法连接此网络问题的,主要是Win10笔记本电脑用户,使用的是无线网络.而出现Win10连接其他无线网络正常,但是就是某个无线网络无法正常连接的时 ...

  6. 2,EasyNetQ-日志记录

    EasyNetQ提供了一个IEasyNetQLogger接口: public interface IEasyNetQLogger { void DebugWrite(string format, pa ...

  7. 【HDU5909】Tree Cutting(FWT)

    [HDU5909]Tree Cutting(FWT) 题面 vjudge 题目大意: 给你一棵\(n\)个节点的树,每个节点都有一个小于\(m\)的权值 定义一棵子树的权值为所有节点的异或和,问权值为 ...

  8. BZOJ.2007.[NOI2010]海拔(最小割 对偶图最短路)

    题目链接 想一下能猜出,最优解中海拔只有0和1,且海拔相同的点都在且只在1个连通块中. 这就是个平面图最小割.也可以转必须转对偶图最短路,不然只能T到90分了..边的方向看着定就行. 不能忽略回去的边 ...

  9. MySQL Replication(Master与Slave基本原理及配置)

    MySQL Replication(Master与Slave基本原理及配置) 1.  主从mysql server的工作原理:(如图及其过程分析) 过程:   Mysql的复制(replication ...

  10. 运维服务器手段(监控宝,Nagios,百度通告平台)

    站在"巨人"的肩膀上运维 现实问题 之前在论坛看到一个运维工程师的帖子,内容如下: "现在的一个IT工作者最头疼的就是加班,秃顶的是IT工作者最多.单身的是IT工作者最多 ...