gpt4 book ai didi

ios - 我如何检测由 CATransaction 触发的动画的完成

转载 作者:可可西里 更新时间:2023-11-01 04:06:38 27 4
gpt4 key购买 nike

我有一个 CALayer,我只是在 Controller 的 initWithNibName 中创建并添加到我的 View Controller 主视图的 subview 中:然后,我执行以下动画:

  [CATransaction begin];
[CATransaction setAnimationDuration:2];
[logoLayer setOpacity:0];
[CATransaction commit];

我如何知道这个动画何时完成? performSelector:延迟 2 秒。方法似乎不是“正确的方法”。

最佳答案

根据doc , [CATransaction setCompletionBlock:] 可用于您想要的。

它说

The completion block object is guaranteed to be called (on the main thread) as soon as all animations subsequently added by this transaction group have completed (or have been removed.) If no animations are added before the current transaction group is committed (or the completion block is set to a different value,) the block will be invoked immediately.

开始动画事务之前尝试添加类似这样的内容。

[CATransaction setCompletionBlock:^{
// Action after the animation completion
}];

关于ios - 我如何检测由 CATransaction 触发的动画的完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9049410/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com