ios - Make UIImageView Go Up Then Down Swift -


i need make uiimageview animate when screen tapped down when hits top.

this code have got @ moment:

    override func touchesbegan(touches: nsset!, withevent event: uievent!) {         if (cgrectintersectsrect(self.playerimagephone.frame, self.floorimagephone.frame)) {             uiview.animatewithduration(0.4) {                 self.playerimagephone.center = cgpointmake(self.playerimagephone.center.x, self.playerimagephone.center.y - 50)                 println("player jumped")             }         } }      override func touchesended(touches: nsset!, withevent event: uievent!) {         uiview.animatewithduration(0.4) {             self.playerimagephone.center = cgpointmake(self.playerimagephone.center.x, self.playerimagephone.center.y + 50)             println("player jumped")     } } 

this code working make go down problem allows user hold finger on screen , image stay up. how can make go down image finished going up?

thanks

touchesbegan can called often... isn't idea perform animations in there. you'll want update seperate object maintaining animation, once animation done (once duration over) run animation bring image down.

as alternative can use use animatewithduration:animations:completion: , calling down animation within completion block.


Comments

Popular posts from this blog

.htaccess - htaccess convert request to clean url and add slash at the end of the url -

php - facebook and github login HWIOAuthBundle and FOSUserBundle in Symfony2.1 -

hadoop - Sqoop installation export and import from postgresql -