How to make this complex animation repeat and autoreverse?
Is there any way to add options UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat to this animation sequence?
[UIView animateWithDuration:1.0f animations:^{
someView.frame = someFrame1;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.5f animations:^{
someView.frame = someFrame2;
} completion:nil];
}];
To animation from point 1 to 2 to 3 to 2 to 1 and repeat, you can do use
animateKeyframesWithDurationin iOS 7 and later:If using auto-layout, you can animate the changing of the constraint constants:
Or, the approach with auto layout is to deactivate the constraints, and then you can animate using
framevalues or what have you.In earlier versions of iOS, you can use
CAKeyframeAnimation, for example to animate along a path:You can do this with however many points you want. This also useful technique if you want to animate along a curved path (e.g. a circle or bezier curve).
To just animate between two points, you can use
animateWithDuration:delay:options:animations:completion:, such as:This animates the movement of
someViewfrom the starting frame tosomeFrame1and back.By the way, using
UIViewAnimationOptionCurveEaseInOutin conjunction withUIViewAnimationOptionAutoreverseandUIViewAnimationOptionRepeatwill give you a smoother effect as the animation reverses and repeats.