I have this insane piece of code. How do I animate this with Core Animation so I have way less code? I have found some code for doing "wiggle" animation but that's in 3D, I just want the view to move side to side, I don't want to animation it bouncing on the 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
}
];
}
];
}
];
}
];
I wanted to follow up with this question in case anyone stumbles onto it. I'm now using 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"];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With