0

我有一段音频和相关的播放和停止按钮,当按下播放按钮时,我使用光标的动画来表示在给定时刻我们在音频样本中的哪个点。每当按下停止按钮时,我希望我的光标返回其初始坐标。我相信 UIViewAnimationOptionBeginFromCurrentState 可能是这样做的方法?我的初始动画代码如下,有人对如何使用 UIViewAnimationOptionBeginFromCurrentState 将光标发送回其原始坐标有任何提示吗?

提前感谢您的帮助:)

    [UIView beginAnimations:@"MoveView" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [UIView setAnimationDuration:2.0f];
    yellowBar.frame = CGRectMake(310, 20, 5, 100);
    [UIView commitAnimations];
4

3 回答 3

6

如果您仍在使用 beginAnimations/commitAnimations,请使用setAnimationBeginsFromCurrentState:. 否则,您可以将 UIViewAnimationOptionBeginFromCurrentState 传递给animateWithDuration:delay:options:animations:completion:options 参数。

于 2012-01-06T18:18:20.207 回答
2

布赖恩是对的,你有两种选择:

//Initialize newFrame here

[UIView animateWithDuration:0.5
                      delay:0.0
                    options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState //Multiple options
                 animations:^ {

                     [yourView setFrame: newFrame];
                 }
                 completion:^ (BOOL finished) {

                 }];

或者

//Initialize newFrame here

[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.5];

    [yourView setFrame: newFrame];

[UIView commitAnimations];
于 2012-11-16T14:00:44.333 回答
0

AFAIK 您只能将该选项与基于块的动画一起使用(无论如何都鼓励您使用)。您将使用此处animateWithDuration:delay:options:animations:completion:描述的方法。

于 2012-01-06T18:15:51.473 回答