0

我想以新闻的形式为 UILabel 制作动画...例如:- 你好吗是我的 UILabel 。我希望它向左移动并在最后一个单词完全向左移动后循环。如果有人可以帮助我吗?

谢谢

4

3 回答 3

0
[UIView animateWithDuration:0.3 animations:^{
    label.frame = frame;
}];

'frame' 应该是标签的新框架。您可以使用此方法对所有 UIKit 视图的更改进行动画处理。

于 2013-06-21T16:45:33.677 回答
0

你试过什么了?

看看UIView的动画方法,比如animateWithDuration:animations:completion:. 您可以为视图设置动画frame,并使用完成处理程序调用另一个方法将视图移回。

本质上,将animate方法视为一种方式,而完成处理程序则视为另一种方式。在计时器/循环上调用整个事物,您将让它不断地来回运行

于 2013-06-21T16:35:39.847 回答
0

在提问之前请先做一些基础知识。

无论如何,有两种常见的方法可以实现这一目标。

  • 使用animateWithDuration:animations:completion:,您可以通过它将标签添加到视图并通过在动画中设置目标帧来制作动画: block.Like:

    //set initial frame for the label and add to the self.view
    [UIView animateWithDuration:/*animation duration*/ animations:^{
        //set destination frame of the label, only change x-axis value
    } completion:^(BOOL finished) {
    
    }];
    
  • 或者,如果您想要此动画的连续循环,您可以使用NSTimer 。例如:

    [NSTimer scheduledTimerWithTimeInterval:/*label_change_time*/ target:nil selector:@selector(moveLabelToLeft:) userInfo:nil repeats:YES];
    

并在moveLabelToLeft 中:设置 x 轴值在 label_change_time 上的差异

于 2013-06-21T16:58:51.647 回答