gpt4 book ai didi

iphone - 有没有办法暂停 CABasicAnimation?

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

我有一个基本的 iPhone 旋转动画。有什么方法可以“暂停”动画以便保持 View 的位置吗?我想这样做的一种方法是使动画“完成”而不是调用“删除”,我该怎么做?

CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2];
rotationAnimation.duration = 100;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = HUGE_VALF;
rotationAnimation.removedOnCompletion = NO;
rotationAnimation.fillMode = kCAFillModeForwards;
[myView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];

最佳答案

最近出现了Apple的技术说明QA1673描述如何暂停/恢复图层的动画。

暂停和恢复动画列表如下:

-(void)pauseLayer:(CALayer*)layer
{
CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
layer.speed = 0.0;
layer.timeOffset = pausedTime;
}

-(void)resumeLayer:(CALayer*)layer
{
CFTimeInterval pausedTime = [layer timeOffset];
layer.speed = 1.0;
layer.timeOffset = 0.0;
layer.beginTime = 0.0;
CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
layer.beginTime = timeSincePause;
}

编辑:iOS 10 引入了新的 API - UIViewPropertyAnimator,它允许以更具交互性的方式处理动画,例如,它可以轻松暂停和恢复动画或“寻求”动画到某个特定的进度值。

关于iphone - 有没有办法暂停 CABasicAnimation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2306870/

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