【发布时间】:2026-01-11 09:50:02
【问题描述】:
我在 Objective-c 上编程。我可以使用 CABasicAnimation 为同时使用 2 个动画的对象创建动画吗?例如,物体同时在缩放和晃动。
【问题讨论】:
标签: objective-c ios animation cabasicanimation
我在 Objective-c 上编程。我可以使用 CABasicAnimation 为同时使用 2 个动画的对象创建动画吗?例如,物体同时在缩放和晃动。
【问题讨论】:
标签: objective-c ios animation cabasicanimation
当然。实际上,您可以使用 CAKeyFrame、CABasic 甚至 UIView 动画来实现。这应该很好用modified from this answer
- (void)earthquake:(UIView*)itemView
{
CGFloat t = 2.0;
CGAffineTransform leftQuake = CGAffineTransformTranslate(CGAffineTransformIdentity, t, -t);
CGAffineTransform rightQuake = CGAffineTransformTranslate(CGAffineTransformIdentity, -t, t);
itemView.transform = leftQuake; // starting point
[UIView beginAnimations:@"earthquake" context:itemView];
[UIView setAnimationRepeatAutoreverses:YES]; // important
[UIView setAnimationRepeatCount:5];
[UIView setAnimationDuration:0.07];
[UIView setAnimationDelegate:self];
itemView.transform = rightQuake; // end here & auto-reverse
[UIView commitAnimations];
[UIView animateWithDuration:1.00 animations:^{
itemView.alpha = 0.0f;
}];
}
【讨论】: