I have a UIImageView that contains an animated picture (sequence of pictures) i'm trying to move the UIImageView from its current position to the right of the screen (from middle to right of the screen) to create a running effect of the character
when i press the button that i want to trigger the animation the image suddenly disappear then get animated from the left side off the screen to the middle. I have no idea why the UIImageView is being moved off the screen (left side)
this is my code
@IBAction func correctButtonPressed(sender: AnyObject) {
if isTrue {
winAudio.play()
playRunAnimation()
UIView.animateWithDuration(3, animations: { () -> Void in
var frame = self.animatedImage.frame
frame.origin.x += (self.animatedImage.superview?.frame.width)!
self.animatedImage.frame = frame
})
}
}
EDIT :
this is how i animate my UIImageView
func playIdelAnimation() {
self.image = UIImage(named: "Idel1.png")
var imageArray = [UIImage]()
for i in 1...10 {
let str = "Idle\(i).png"
let imageName = UIImage(named: str)!
imageArray.append(imageName)
}
self.animationImages = imageArray
self.animationDuration = 0.5
self.startAnimating()
}
self.image = UIImage(named: "Idel1.png") is to set a default picture for the UIImageView then im creating an array of UIImage to animate it in the UIImageView
using (self) because i have a custom class for the UIImageView