I want my textFields to hid behind the screen when "viewDidLoad" calls and then appearing smoothly on view by pushing a button. I just have a function like:
UIView.animate(duration: 0.5, options: .curveEaseIn) {
textField.center.x -= view.frame.width
}
And it was working until added constraints. And now the textField just hiding behind the screen and returning back immediately. I think solution in using "Dispatch.main" but i didn't have success. Click here to look
Can somebody help with it?
Edited
I have a similar app with the same animation and it works with all constraints. Thats the code and Storyboard. Why it possible to do with UIView?
You cannot change the
frameof a view that is using constraints for auto-layout.Instead, you need to animate changes to the constraints.
Various ways to do this -- here is one approach.
In Storyboard, layout your fields like this:
Each field has a
CenterXconstraint... but we will set the Priority toHigh (750):Then, we'll add "hidden" constraints as properties in the view controller:
and in
viewDidLoadwe'll create Priority : Required constraints to start those fields "off-screen." To animate the fields into-view, we can deactivate the "hidden" constraints and let auto-layout use the Storyboard-created CenterX constraints.Here's some example code:
and here's the source code for that Storyboard: