//Viewcontroller.swift//Animations//Created by WZ on 16/1/15.//copyright©2016 year iwangzheng.com. All rights reserved.Import UIKitclassViewcontroller:uiviewcontroller {var count=1var timer=Nstimer () var isanimating=true@IBOutlet weak var image:uiimageview!@IBAction func nextbtn (sender:anyobject) {ifIsanimating = =true{timer.invalidate () isanimating=false }Else{Timer= Nstimer.scheduledtimerwithtimeinterval (0.1, Target:self, Selector:selector ("doanimaition"), Userinfo:nil, repeats:true) isanimating=true } } Overridefunc viewdidload () {super.viewdidload () Timer= Nstimer.scheduledtimerwithtimeinterval (0.1, Target:self, Selector:selector ("doanimaition"), Userinfo:nil, repeats:true)} func doanimaition () {ifCount <4{Count++ }Else{Count=1} image.image= UIImage (named:"\ (count)") } Overridefunc didreceivememorywarning () {super.didreceivememorywarning ()//Dispose of any resources the can be recreated. } /*override func Viewdidlayoutsubviews () {//Image.center = Cgpointmake (image.center.x-400, IMAGE.CENTER.Y) From left to right//image.alpha = 0//from scratch Image.frame = CGRectMake (100, 20, 0, 0)//change size} override func Viewdida Ppear (Animated:bool) {uiview.animatewithduration (1,animations: {(), Void in//self. Image.center = Cgpointmake (self. Image.center.x +, self. IMAGE.CENTER.Y)//self. Image.alpha = 1 self. Image.frame = CGRectMake ( +,-)})}*/}
GIF animation effect-swift