gpt4 book ai didi

ios - UIView帧动画 "wiggle"

转载 作者:可可西里 更新时间:2023-11-01 05:14:45 27 4
gpt4 key购买 nike

我有这段疯狂的代码。我如何使用 Core Animation 为它制作动画,这样我的代码就更少了?我找到了 some code制作“摆动”动画,但那是 3D 形式,我只想让 View 左右移动,我不想让它在两侧弹跳。

[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
}
];
}
];
}
];
}
];

最佳答案

我想跟进这个问题,以防有人无意中发现它。我现在正在使用关键帧:

-(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"];
}

关于ios - UIView帧动画 "wiggle",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11420746/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com