如何实现 UIViewAnimationOptionBeginFromCurrentState

发布于 2024-12-25 00:53:54 字数 511 浏览 1 评论 0原文

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

感谢您提前提供任何帮助:)

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

I have a piece of audio & associated Play & Stop buttons, when the Play button is pressed I use an animation of a curser to denote at which point in the audio sample we are, at a given moment. Whenever the stop button is pressed I want my curser to return to its initial coordinates. I believe UIViewAnimationOptionBeginFromCurrentState might be the way to do this? My code for the initial animation is below, anyone have any tips on how to use UIViewAnimationOptionBeginFromCurrentState in order to send the cursor back to its original coordinates?

Thanks for any help in advance :)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

大海や 2025-01-01 00:53:54

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

If you are still using beginAnimations/commitAnimations, use setAnimationBeginsFromCurrentState:. Otherwise, you can pass UIViewAnimationOptionBeginFromCurrentState to animateWithDuration:delay:options:animations:completion: for the options parameter.

谜兔 2025-01-01 00:53:54

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

//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];

Brian is right, you have got two alternatives:

//Initialize newFrame here

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

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

                 }];

Or

//Initialize newFrame here

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

    [yourView setFrame: newFrame];

[UIView commitAnimations];
孤千羽 2025-01-01 00:53:54

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

AFAIK you can only use that option with block-based animations (which you are encouraged to use anyway). You'd use the animateWithDuration:delay:options:animations:completion: method, described here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文