Imbue
Imbue

Reputation: 429

imageView animation gone wrong

I have an animation on my imageView that should be animating the imageView to slideup on tap. Problem is, that when I tap the first time, it jumps down from y by 200 px, and then animates back to zero. Second time I tap, the animation does exactly what it should do, and moves up, by negative 200px.

It makes absolutely no sense to me that it works the second time, but not the first time. I've tried setting the origin of the imageView to 0,0, to have a starting point, as I thought this was causing the jump, and the weird animation, but same deal.

UIView.animateWithDuration(10.0, animations: {() -> Void in

        self.imageView.frame = CGRectMake(self.imageView.frame.origin.x, -200, self.imageView.frame.size.width, self.imageView.frame.size.height)
    })

Upvotes: 0

Views: 50

Answers (1)

Pranav Wadhwa
Pranav Wadhwa

Reputation: 7736

As mentioned in the comments, you have a constraint. Connect that constraint to your code, and update it in your animation. Then run self.view.layoutIfNeeded()

UIView.animateWithDuration(Double(0.5), animations: {
    self.yourConstraint.constant = //Whatever
    self.view.layoutIfNeeded()
})

Upvotes: 1

Related Questions