代码改变世界

Cocoa Touch 移动控件动画

2012-08-23 15:11  Y_York  阅读(212)  评论(0编辑  收藏  举报
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];