gpt4 book ai didi

iphone - CALayer 的动画结束回调?

转载 作者:行者123 更新时间:2023-12-03 18:09:11 24 4
gpt4 key购买 nike

我想知道 CALayer 中动画的回调在哪里(或者是否有任何东西)。具体来说,对于隐式动画,例如更改框架、位置等。在 UIView 中,您可以执行以下操作:

[UIView beginAnimations:@"SlideOut" context:nil];
[UIView setAnimationDuration:.3];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animateOut:finished:context:)];
CGRect frame = self.frame;
frame.origin.y = 480;
self.frame = frame;
[UIView commitAnimations];

具体来说,setAnimationDidStopSelector 是我想要的 CALayer 动画。有这样的事吗?

TIA。

最佳答案

您可以使用 CATransaction,它有一个完成 block 处理程序。

[CATransaction begin];
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
[pathAnimation setDuration:1];
[pathAnimation setFromValue:[NSNumber numberWithFloat:0.0f]];
[pathAnimation setToValue:[NSNumber numberWithFloat:1.0f]];
[CATransaction setCompletionBlock:^{_lastPoint = _currentPoint; _currentPoint = CGPointMake(_lastPoint.x + _wormStepHorizontalValue, _wormStepVerticalValue);}];
[_pathLayer addAnimation:pathAnimation forKey:@"strokeEnd"];
[CATransaction commit];

关于iphone - CALayer 的动画结束回调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/296967/

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