Swift-Animated effects of multiple mask
Effect
Source
Https://github.com/YouXianMing/Swift-Animations
////Tranformfadeview.swift//swift-animations////Created by youxianming on 16/8/20.//copyright©2016 year youxianming. All rights reserved.//Import UIKitenumTranformfadeviewanimatedtype:int { CaseFade, Show}//Mark:tranformfadeviewclassTranformfadeview:uiview {//mark:convenience init.convenience init (frame:cgrect, Verticalcount:int, Horizontalcount:int, Fadeduradtion:nstimeinterval, an Imationgapduration: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{returnImageview.image}Set(newval) {imageview.image =newval}} ///The content ImageView ' s contentmode.var Imagecontentmode:uiviewcontentmode {Get{returnImageview.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.0var fadeduradtion:nstimeinterval! =1 ///the animation duration and subviews from Allmaskview, default is 0.2var animationgapduration:nstimeinterval! =0.2 /** make the config effective. */func makeconfigeffective () {ifVerticalcount <1|| Horizontalcount <1 { return; } ifAllmaskview! =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=0 forHorizontalinch 0.. <Horizontalcount { forVerticalinch 0.. <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 +1; }} Maskviewcount=Count forIinch 0.. <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) {ifAnimated = =true{Let tmpfadeduradtion= Fadeduradtion <0?1.0: fadeduradtion Let Tmpgapduration= Animationgapduration <0?0.2: Animationgapduration forIinch 0.. <Maskviewcount {Let Tmpview= Allmaskview.viewwithtag (Maskviewtag +i) uiview.animatewithduration (tmpfadeduradtion, Delay:nstimeinterval (i)*tmpgapduration, Options:. Curvelinear, animations: {SwitchTransformto { Case . Fade:tmpview?. Alpha =0.0 Case . Show:tmpview?. Alpha =1.0}} , Completion:nil)}} Else { forIinch 0.. <Maskviewcount {Let Tmpview= Allmaskview.viewwithtag (Maskviewtag +i)SwitchTransformto { Case . Fade:tmpview?. Alpha =0.0 Case . Show:tmpview?. Alpha =1.0 } } } } //Mark:system Methods & Private Properties Privatevar imageview:uiimageview!Privatevar allmaskview:uiview!Privatevar maskviewcount:int!Privatevar Countnumarray: [int]!Privatevar maskviewtag:int = + OverrideInit (frame:cgrect) {super.init (frame:frame) ImageView=Uiimageview (frame:bounds) imageView.layer.masksToBounds=trueCountnumarray=[Int] () Self.addsubview (ImageView)} required init?(coder Adecoder:nscoder) {fatalerror ("Init (coder:) has not been implemented") }}
Swift-Multiple mask animations