2

I'm trying animations and I'm facing a big problem: when my animation finished and I do something ( touch the screen, etc), the elements reset their positions to their first position. I found this: [blog]: Animation Blocks resets to original position after updating text they say it's because elements have constraints or auto layout so turn it off to fix it but I don't want to turn it off. Can we update constraints programmatically? is there an other solution?

here's my animation:

@IBOutlet var tfUser: UITextfiled!

 override func viewDidLoad() {
    super.viewDidLoad()

}

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
tfUser.center.x += view.bounds.width
}


override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

     UIView.animateWithDuration(2, delay: 1.8, options: [.CurveEaseInOut], animations: {
        self.tfUser.center.x += self.view.bounds.width
        //self.tfUser.frame = CGRectMake(0, 233, 375 , 89)
       // i tried CGRectMake but it delete the animation
        }, completion: nil)
}
Community
  • 1
  • 1
Matt
  • 147
  • 1
  • 13

1 Answers1

1

In comment of my question , @Hardik Shekhat told to use :

self.tfUser.translatesAutoresizingMaskIntoConstraints = true

it works for me !

Hardik Shekhat
  • 1,680
  • 12
  • 21
Matt
  • 147
  • 1
  • 13