Swift - 多个mask的动画效果
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的动画效果的更多相关文章
- Swift - 用UIScrollView实现视差动画效果
Swift - 用UIScrollView实现视差动画效果 效果 源码 https://github.com/YouXianMing/Swift-Animations // // MoreInfoVi ...
- Swift - 使用atlas图集实现动画效果(SpriteKit游戏开发)
我们通常继承SKSpriteNode来实现游戏中的元素,除了可以使用图片作为纹理皮肤外.我们还可以使用动画纹理集来实现动画播放. 动画纹理集的制作也很简单,首先要有一套动画序列图,然后把它们放到一个文 ...
- Swift 添加到TableView实现动画效果
let indexPath = NSIndexPath(forRow:0 ,inSection:0) self.tableView.insertRowsAtIndexPaths([indexPath] ...
- Swift - CALayer的contents属性动画
Swift - CALayer的contents属性动画 效果 源码 https://github.com/YouXianMing/Swift-Animations // // LiveImageVi ...
- iOS开发——动画篇Swift篇&动画效果的实现
Swift - 动画效果的实现 在iOS中,实现动画有两种方法.一个是统一的animateWithDuration,另一个是组合出现的beginAnimations和commitAnimation ...
- Swift - 使用CABasicAnimation实现动画效果
1,CABasicAnimation类只有三个属性: fromValue:开始值 toValue:结束值 Duration:动画的时间 2,通过animationWithKeyPath键值对的方式设置 ...
- [Swift通天遁地]五、高级扩展-(11)图像加载Loading动画效果的自定义和缓存
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Swift 带有动画效果的TabBarItem
额...貌似挺长时间没有总结新知识了,最近在看swift,之前swift刚出来的时候大体看了一遍,后来时间长了没看加之swift2.0做了比较大的调整,公司项目也不是用swift写的,也就没怎么看了, ...
- Swift - 动画效果的实现方法总结(附样例)
在iOS中,实现动画有两种方法.一个是统一的animateWithDuration,另一个是组合出现的beginAnimations和commitAnimations.这三个方法都是类方法. 一,使用 ...
随机推荐
- LeetCode(15):三数之和
Medium! 题目描述: 给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组. 注意:答 ...
- sql语句添加查询字段
SELECT * FROM( SELECT ROW_NUMBER() OVER (ORDER BY r.UpdateTime desc) tempRowNum,h.BizID,h.OrgID FROM ...
- explain的使用
MySQL 提供了一个 EXPLAIN 命令, 它可以对 SELECT 语句进行分析, 并输出 SELECT 执行的详细信息, 以供开发人员针对性优化. mysql. row ************ ...
- The last access date is not changed even after reading the file on Windows 7
https://superuser.com/questions/251263/the-last-access-date-is-not-changed-even-after-reading-the-fi ...
- jQuery库冲突
jQuery库冲突解决办法 一次面试中面试官问到jQuery和别的库冲突怎么解决?虽然以前看过,但是我已经不记得了. 我的思路就是如果让我来设计,那我就用一个默认值$,不传参数,那就用$,最后就挂 ...
- hadoop2.6.4集群的搭建
hadoop集群搭建(亲自操作成功步骤!值得信赖!) 1.1集群简介 hadoop的核心组件: HDFS(分布式文件系统) YARN(运算资源调度系统) MapReduce(分布式运算编程框架) HA ...
- 出现The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path错误
实际上就是tomcat没有配置的原因 先去http://tomcat.apache.org 下载tomcat 然后根据http://jingyan.baidu.com/article/8065f87f ...
- Spring拦截器和过滤器
什么是拦截器 拦截器(Interceptor): 用于在某个方法被访问之前进行拦截,然后在方法执行之前或之后加入某些操作,其实就是AOP的一种实现策略.它通过动态拦截Action调用的对象,允许开发者 ...
- 007.Zabbix监控图形绘制
一 Graphs配置 1.1 新建图形 Graphs是将数据展示为图像,以视觉化形式展示,Graphs的配置保存在主机和模板中. Configuration---->Hosts---->G ...
- Redis集群主从复制(一主两从)搭建配置教程【Windows环境】
如何学会在合适的场景使用合适的技术方案,这值得思考. 由于本地环境的使用,所以搭建一个本地的Redis集群,本篇讲解Redis主从复制集群的搭建,使用的平台是Windows,搭建的思路和Linux上基 ...