1

我是 Xcode 和 Objectice C 的新手,希望对我的应用程序有所帮​​助。我想为按钮添加翻译动画。例如,将“按钮”从 X:30 Y:50 移动到 X:10 Y:70 的代码是什么?谢谢 :)。

4

2 回答 2

12

对于旧的编译器/iOS:

// set the original frame
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];

对于较新的编译器/iOS:

// set the original frame
button.frame = CGRectMake(30, 50, 100, 100);

// animate
[UIView animateWithDuration:0.75 animations:^{
    button.frame = CGRectMake(10, 70, 100, 100);
}];
于 2012-08-01T20:16:29.517 回答
0

UIView(UIButton 的超类)具有动画的能力,使用如下所示。

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2];
CGAffineTransform transform = CGAffineTransformMakeTranslation(-20, 20);
[aButton setTransform:transform];
[UIView commitAnimations];
于 2012-08-01T20:18:44.917 回答