1.传统的动画写法
//beginAnimations:context:
//前一个参数是为这个动画命名 第一个参数是获取动画的上下文
[UIView beginAnimations:@"testAnmation" context:nil];
//动画运行所需的时间
[UIView setAnimationDuration:0.5];
//调用代理方法来监听这个视图
[UIView setAnimationDelegate:self];
//用setAnimationDidStopSelector:这个方法可以在当前动画结束时来调用下一个方法
[UIView setAnimationDidStopSelector:@selector(当动画结束后你需要调用的方法)];//动画结束后调用的方法
CGRect frame = 你现在需要动画的视图.frame;
frame.origin.x = 280+100;
你现在需要动画的视图.frame = frame;
[UIView commitAnimations];//结束动画
2.利用Block来使用UIView动画
[UIView animateWithDuration:0.5 animations:^{//动画1
CGRect frame = 你现在需要动画的视图.frame;
frame.origin.x = 280+100;
你现在需要动画的视图.frame = frame;
} completion:^(BOOL finished) {//动画2
if (finished) {
[UIView animateWithDuration:0.5 animations:^{//动画2的动画运行时间
CGRect frame = 你现在需要动画的视图.frame;
frame.origin.x = 280-280;
你现在需要动画的视图.frame = frame;
}];
}
}];