ios 4.0之后的方法
// set the original frame
button.frame =CGRectMake(30,50,100,100);
// animate
[UIView animateWithDuration:0.75 animations:^{
button.frame =CGRectMake(10,70,100,100);}];
旧版方法为:
button.frame =CGRectMake(30,50,100,100);
// animate to the new one
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.75];
button.frame =CGRectMake(10,70,100,100);
[UIView commitAnimations];
另外,使用控件的setTransform方法也可以,只要设置x,y方向上的相对位移就可以了:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2];
CGAffineTransform transform =CGAffineTransformMakeTranslation(-20,20);
[aButton setTransform:transform];
[UIView commitAnimations];