UIView radial animation "wiggle"

I have this crazy piece of code. How do I animate this with Core Animation, so I have less code? I found some code for creating a wiggle animation, but in 3D, I just want the view to move side to side, I don't want the animation to bounce around on its sides.

[UIView animateWithDuration:0.1f animations:^{ CGRect frame = tableView.frame; frame.origin.x -= 4; tableView.frame = frame; } completion:^(BOOL finished) { [UIView animateWithDuration:0.1f animations:^{ CGRect frame = tableView.frame; frame.origin.x += 4; tableView.frame = frame; } completion:^(BOOL finished) { [UIView animateWithDuration:0.1f animations:^{ CGRect frame = tableView.frame; frame.origin.x -= 4; tableView.frame = frame; } completion:^(BOOL finished) { [UIView animateWithDuration:0.1f animations:^{ CGRect frame = tableView.frame; frame.origin.x = 0; tableView.frame = frame; } completion:^(BOOL finished) { // Nothing } ]; } ]; } ]; } ]; 
+4
source share
2 answers

This question is a very concise way to perform repeated motion tweens. I used it for rotation, but you can apply any transformation, in your case, translation

0
source

I wanted to continue this question if someone stumbles upon it. Now I use key frames:

 -(void)wiggleView { CAKeyframeAnimation *animation = [CAKeyframeAnimation animation]; animation.keyPath = @"position.x"; animation.values = @[ @0, @8, @-8, @4, @0 ]; animation.keyTimes = @[ @0, @(1 / 6.0), @(3 / 6.0), @(5 / 6.0), @1 ]; animation.duration = 0.4; animation.additive = YES; [self.layer addAnimation:animation forKey:@"wiggle"]; } 
+8
source

All Articles