iOS - 标签或图像的动画移动

Nip*_*rus 13 animation ios4 ios

如何设置标签或图像的移动动画?我只想从屏幕上的一个位置慢慢过渡到另一个位置(没什么特别的).

Hja*_*mar 13

对于ios4及更高版本,您不应使用beginAnimations:contextcommitAnimations,因为文档中不鼓励这些.

相反,您应该使用其中一个基于块的方法.

上面的例子看起来像这样:

[UIView animateWithDuration:0.3 animations:^{  // animate the following:
    myLabel.frame = newRect; // move to new location
}]; 
Run Code Online (Sandbox Code Playgroud)


Dav*_*har 12

你正在寻找UIView的方法-beginAnimations:context:-commitAnimations方法.

简而言之,您可以执行以下操作:

[UIView beginAnimations:nil context:NULL]; // animate the following:
myLabel.frame = newRect; // move to new location
[UIView setAnimationDuration:0.3];
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)