我有这段疯狂的代码。我如何为Core Animation制作动画,这样我的代码就少了?我发现some code用于做“摆动”动画,但这是3D,我只想让视图左右移动,我不想动画它在两侧弹跳。UIView帧动画“摆动”
[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
}
];
}
];
}
];
}
];
尝试[这个问题的回答(http://stackoverflow.com/questions/929364/how-to-create-iphones-wobbling-icon-effect),我用它和它很好。 – 2012-07-10 19:46:48
不是我要做的。我*只*想要水平来回激活视图的位置,我不想让它晃动/摆动。不过谢谢! – runmad 2012-07-10 19:50:34
虽然你可以使用类似的方法,只需要改变从旋转到翻译的转换 – 2012-07-10 19:51:28