How can I animate one StackView
so that it slides up starting from x=0
to y=500
? I have the following method viewDidLoad()
that does an effect that grows the StackView
:
StackView.transform = CGAffineTransformMakeScale(0.0, 0.0)
and then I added a growing effect in the method viewDidAppear()
:
UIView.animateWithDuration(0.4, delay: 0.0, options: [], animations: {
self.StackView.transform = CGAffineTransformIdentity
}, completion: nil)
Then the method executes the viewDidLoad
and the StackView
is reduced to the minimum size. When the method of viewDidLoad
completes, the method viewDidAppear
is invoked, and the animation begins and the method StackView
begins to grow. The animation stops when the StackView
reaches its original size.
Although it's a nice effect, it's not what I want to achieve. I want the animation to slide from x= 0
and stop at y=500
. I tried to add the following code in viewDidLoad
it to achieve it, but I still get the same growing effect:
StackView.transform = CGAffineTransformMakeTranslation(0, 500)
Any suggestions on how to achieve this?
I would set ones
constraints
that define the starting position of thestackview
, for examplebottomConstraint
andleadingConstraint
.You
leading
can leave it with the final value, since if I have understood you correctly, you want to animate the Y axis.so
viewDidLoad
you could animate the change of the constraintbottomConstraint
Assuming your stackview has a height of 200, set your
bottomConstraint
in the storyboard to a value of -200, so it's off screen.Then you can play with the values as you like to achieve the desired effect.
What you want is that when you slide up the animation starts, right?
Try this to see if it does what you need.