如何为按钮设置动画?(目标c)

Fer*_*mán 1 xcode animation translation objective-c button

我是Xcode和Objectice C的新手,会对我的应用程序提供一些帮助.我想为按钮添加翻译动画.例如,从X:30 Y:50到X:10 Y:70移动"按钮"的代码是什么?谢谢 :).

小智 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];
Run Code Online (Sandbox Code Playgroud)

对于较新的编译器/ 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);
}];
Run Code Online (Sandbox Code Playgroud)