iPhone - 捕捉分组动画的结尾

发布于 2024-12-07 17:26:34 字数 262 浏览 0 评论 0原文

我对 2 个视图进行动画处理,每个视图都有其包含 2 个 CAAnimation 的 CAAnimationGroup。它们同时启动(如果计算时间可以忽略不计),并且具有相同的持续时间。

我怎样才能知道两个分组动画何时完成。

我放置了 - (void)animationDidStop:(CAAnimation *)theAnimation finish:(BOOL)flag 委托方法,但是...我可以测试什么?听起来很简单,但我不知道这样做的方法。

I animate 2 views, each one with its CAAnimationGroup that contains 2 CAAnimations. They are launched at the same time (if computing time is negligible), and have the same duration.

How may I do to know when both grouped animation is finished.

I put the - (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag delegate method, but... What may I test ? Sounds simple, but I don't see the way of doing this.

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

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

发布评论

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

评论(1

水中月 2024-12-14 17:26:34

您可以使用两个变量来跟踪动画是否已完成:

BOOL firstAnimFinished;
BOOL secondAnimFinished;

然后在animationDidStop 委托中检查哪个动画正在调用该方法并相应地设置标志。问题是,当动画调用委托时,您需要添加一个键来识别动画(您创建的动画不会是调用委托的动画,这是另一个问题/咆哮的主题)。例如:

// when you create the animations
[firstAnmim setValue: @"FirstAnim" ForKey: @"Name"];
[secondAnmim setValue: @"SecondAnim" ForKey: @"Name"];

// Your delegate
- (void)animationDidStop:(CAAnimation*)theAnimation finished:(BOOL)flag {
    NSString* name = [theAnimation valueForKey: @"Name"];
    if ([name isEqualToString: @"FirstAnim"]) {
        firstAnimFinished = YES;
    } else if ([name isEqualToString: @"SecondAnim"]) {
        secondAnimFinished = YES;
    }
    if (firstAnimFinished && secondAnimFinished) {
        // ALL DONE...
    }
}

You can use two variables to track whether the animations have completed:

BOOL firstAnimFinished;
BOOL secondAnimFinished;

then in your animationDidStop delegate you check which animation is calling the method and set the flags appropriately. The catch is that you'll need to add a key to identify the animations when they call the delegate (the animations you created will not be the ones calling the delegate, which is a subject for another question/rant). For example:

// when you create the animations
[firstAnmim setValue: @"FirstAnim" ForKey: @"Name"];
[secondAnmim setValue: @"SecondAnim" ForKey: @"Name"];

// Your delegate
- (void)animationDidStop:(CAAnimation*)theAnimation finished:(BOOL)flag {
    NSString* name = [theAnimation valueForKey: @"Name"];
    if ([name isEqualToString: @"FirstAnim"]) {
        firstAnimFinished = YES;
    } else if ([name isEqualToString: @"SecondAnim"]) {
        secondAnimFinished = YES;
    }
    if (firstAnimFinished && secondAnimFinished) {
        // ALL DONE...
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文