I am trying to chain a set of UIView animateWithDuration:
using the flag UIViewAnimationOptionRepeat
The animation steps I am trying to repeat are:
- Animate a
UIView
100 pixels to the left - Fade the
UIView
out (opacity'0'
) - While faded out (invisible), move it back to the original position (100 px to the right)
- Fade the
UIView
back in (set opacity to'1'
) - Repeat the animation using flag
UIViewAnimationOptionRepeat
I am not able to repeat the whole chain of animations - and only able to repeat the top most animation.
The code I have tried is this:
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionRepeat animations:^{
self.handImageView.frame = CGRectMoveByXPixels(self.handImageView.frame, -100);
[UIView animateWithDuration:0.5 delay:1 options:0 animations:^{
self.handImageView.alpha = 0;
} completion:^(BOOL finished) {
self.handImageView.frame = CGRectMoveByXPixels(self.handImageView.frame, 100);
[UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
self.handImageView.alpha = 1;
} completion:^(BOOL finished) {
}];
}];
} completion:^(BOOL finished) {
}];