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

C# random value from dictionary and tuple -

cgi - How do I interpret URLs without extension as files rather than missing directories in nginx? -

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