Quartz 2D Affine Transformation Sequence

I am trying to simulate incorrect password input animation in OS X using UIAlertView in iOS. Essentially, I want this to translate the warning to the left, and then translate it correctly. That's what I'm doing:

[UIView animateWithDuration:0.5 animations:^{ alertView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 200, 0); alertView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, -200, 0); }]; 

However, this does not have the desired effect. A warning shoots to the right instantly, and then smoothly moves to the left. How can I make both translations run smoothly one after another?

+4
source share
1 answer

Try the following:

 [UIView animateWithDuration:0.5 animations:^{ alertView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 200, 0); } completion:^(BOOL finished) { [UIView animateWithDuration:0.5 animations:^{ alertView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, -200, 0); }]; }]; 

But I would do the animation as follows:

 [UIView animateWithDuration:0.1 animations:^{ alertView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 20, 0); } completion:^(BOOL finished) { [UIView animateWithDuration:0.1 animations:^{ alertView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, -20, 0); } completion:^(BOOL finished) { [UIView animateWithDuration:0.1 animations:^{ alertView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0, 0); }]; }]; }]; 

To you !; -)

+8
source

Source: https://habr.com/ru/post/1387888/


All Articles