【发布时间】:2012-07-10 19:44:54
【问题描述】:
我有这段疯狂的代码。如何使用 Core Animation 为它制作动画,这样我的代码就更少了?我发现 some code 用于制作“摆动”动画,但那是 3D 的,我只想让视图左右移动,我不想让它在两边弹跳。
[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
}
];
}
];
}
];
}
];
【问题讨论】:
-
试试this question's answer,我用过,效果很好。
-
也不是我想要的。我只想要水平来回动画视图的位置,我不希望它摆动/摆动。不过谢谢!
-
你可以使用类似的方法,只需将变换从旋转更改为平移
-
当然!多哈。您应该发布作为答案,我会接受:)
-
您不想让它摆动吗?你可能想改变问题的标题。
标签: ios core-animation uiviewanimation