I have been trying to animate a UITextField so that its y position increases by 50px. Basically, it moves up by fifty pixels. This is my code:
@IBAction func textField(sender: AnyObject) {
let x = self.pw.frame.origin.x
let y = self.pw.frame.origin.y + 100
UIView.animateWithDuration(0.5, delay: 0, options: nil, animations: {
self.pw.frame = CGRectMake(x, y, self.pw.frame.size.width, self.pw.frame.size.height)
}, completion: nil)
It is in a textField's delegate. This code is run when the UITextField is tapped.
This code, sadly, does not do what I want it to. When run, it moves the text field up by 50 pixels but then moves it right back down. It does not finish with it up in what is supposed to be its final position.
As mentioned in the comments, you should not manually modify frames when you have autolayout constraints installed. Instead you need to change your constraints to reflect the animation's end result.
The following is a minimal working example. It creates a button and a text field and initially positions the text field 58 points below the end of the button. When you tap the button, the constant on the text field's top spacing constraint is decreased from 58 to 8 to move the text field up.
When you have your constraints set up through Interface Builder you can create an outlet for the top spacing constraint in your view controller and use that to modify the text field's top space.