Issue with flash animation with record button swift -


i trying make record button when user click on , it's start recording , want apply flash animation on button , found this post. , convert code swift not working , here swift code:

var buttonflashing = false @ibaction func record(sender: anyobject) {      println("button tapped")     if !buttonflashing {         startflashingbutton()     } else {         stopflashingbutton()     } }  func startflashingbutton() {      buttonflashing = true     recordbutton.alpha = 1      uiview.animatewithduration(0.5 , delay: 0.0, options: uiviewanimationoptions.curveeaseinout | uiviewanimationoptions.repeat | uiviewanimationoptions.autoreverse | uiviewanimationoptions.allowuserinteraction, animations: {          self.recordbutton.alpha = 0          }, completion: {bool in     }) }  func stopflashingbutton() {      buttonflashing = false      uiview.animatewithduration(0.1, delay: 0.0, options: uiviewanimationoptions.curveeaseinout | uiviewanimationoptions.beginfromcurrentstate, animations: {          self.recordbutton.alpha = 1          }, completion: {bool in     }) } 

it printing "button tapped" first time when press button , animation takes place when press button again "button tapped" not printing console. , can not stop animation.

i can not find wrong here.

the problem code alpha set zero. so, os disables interaction when alpha 0 or hidden. animation applied layer of button, , sets alpha final value. so, set alpha value low 0.1 enable user interaction , should fine.

you either 1 of following options,

set alpha 0.1

uiview.animatewithduration(0.5 , delay: 0.0, options:    [     uiviewanimationoptions.curveeaseinout,      uiviewanimationoptions.autoreverse,     uiviewanimationoptions.repeat,      uiviewanimationoptions.allowuserinteraction   ],    animations: {     self.recordbutton.alpha = 0.1           }, completion: {bool in }) 

or, set color of layer clearcolor seems more sensible in case.

uiview.animatewithduration(0.5 , delay: 0.0, options:    [     uiviewanimationoptions.curveeaseinout,      uiviewanimationoptions.autoreverse,     uiviewanimationoptions.repeat,      uiviewanimationoptions.allowuserinteraction   ],    animations: {     self.recordbutton.layer.backgroundcolor = uicolor.clearcolor().cgcolor          }, completion: {bool in }) 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -