Question

I use this code to move my view

[UIView animateWithDuration:0.3 animations:^{
    [MyView setTransform:CGAffineTransformMakeTranslation(260, 0)];
} completion:^(BOOL finished) {
}];

MyView is a subview of self.view

I want to move it to right with 260

but it will first move to left with 130 and no animate

and then move to right with 260 and animate

I don't know why MyView move to left first?

Was it helpful?

Solution

The problem is that you are using auto layout. For a simple animation, trying turning off auto layout in storyboard.

Your animation should work then as expected.

OTHER TIPS

I guess the problem is that the MakeTranslation function is making your view reset it's position before animating to the new transform.

Try this:

[UIView animateWithDuration:0.3 animations:^{
    [MyView setTransform:CGAffineTransformTranslate(myView.transform, 260, 0)];
} completion:^(BOOL finished) {
}];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top