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. sql语句添加查询字段

    SELECT * FROM( SELECT ROW_NUMBER() OVER (ORDER BY r.UpdateTime desc) tempRowNum,h.BizID,h.OrgID FROM ...

  2. SqlServerDBCC SHRINKFILE不起作用

    检查索引碎片的结果: CREATE DATABASE test_shrink USE test_shrink CREATE TABLE show_extent(a INT,b NVARCHAR(390 ...

  3. vue-cli的工程模板与构建工具

    vue-cli的工程模板与构建工具 https://www.cnblogs.com/yinn/p/9712480.html 脚手架vue-cli系列二:vue-cli的工程模板与构建工具 上篇文章我们 ...

  4. Windows 系统采用批处理命令修改 ip 地址

    Windows 系统采用批处理命令修改 ip 地址 :: 设置IP地址 set /p choice=请选择设置类型(1:外网IP / 2:内网IP / 3:自动获取IP): echo. if &quo ...

  5. 全局查询文件linux

    在工作中,可能突然需要找到某个文件,这个又不知道,需要全局查询一下. 下面是命令行: find / -name "*.log" | xargs grep "elk&quo ...

  6. SQL中的坑

    一.where,group by,having --group by 和having 解释:前提必须了解sql语言中一种特殊的函数:聚合函数, 例如SUM, COUNT, MAX, AVG等.这些函数 ...

  7. 送你一套纯净版的 SSM 架构

    大致介绍一下,目前 Java 中使用比较多的框架组合就是 Spring .Springmvc .Mybatis ,这 3 个框架也就是我们常说的 SSM. 前面陆陆续续也已经介绍完了这 3 个框架,今 ...

  8. css 控制文字超出时显示省略号

    不多说,直接看代码吧: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> & ...

  9. android onPause OnSavedInstance

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 活动 的 在暂停时候 这个方法  执行结束后,才会执行 下一个活动的 在创建时候 的那个 ...

  10. BZOJ.2125.最短路(仙人掌 最短路Dijkstra)

    题目链接 多次询问求仙人掌上两点间的最短路径. 如果是在树上,那么求LCA就可以了. 先做着,看看能不能把它弄成树. 把仙人掌看作一个图(实际上就是),求一遍根节点到每个点的最短路dis[i]. 对于 ...