gpt4 book ai didi

iPhone CAKeyframeAnimation 不更新位置属性?

转载 作者:行者123 更新时间:2023-12-03 20:44:50 24 4
gpt4 key购买 nike

我为图层编写了动画,将图层从一个位置移动到另一个位置:

- (void) animateCentreRightTransition: (int) transition {
float scaleFactor[2] = {1, 0.8};
if (transition == WatchTransitionClockwisePortrait || transition == WatchTransitionClockwiseLandscape) {
scaleFactor[0] = 0.8;
scaleFactor[1] = 1;
}

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
CGMutablePathRef curvedPath = CGPathCreateMutable();
CGPathMoveToPoint(curvedPath, NULL, kCentreRightTrasition[transition][0], kCentreRightTrasition[transition][1]);
CGPathAddCurveToPoint(curvedPath, NULL, kCentreRightTrasition[transition][2], kCentreRightTrasition[transition][3], kCentreRightTrasition[transition][4], kCentreRightTrasition[transition][5], kCentreRightTrasition[transition][6], kCentreRightTrasition[transition][7]);
pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);

CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath: @"transform.scale"];
scale.fromValue = [NSNumber numberWithDouble:scaleFactor[0]];
scale.toValue = [NSNumber numberWithDouble:scaleFactor[1]];

CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = [NSArray arrayWithObjects:scale, pathAnimation, nil];
group.autoreverses = NO;
group.duration = kWatchTransitionDuration;
group.repeatCount = 1;
group.removedOnCompletion = NO;
group.fillMode = kCAFillModeForwards;
group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
group.delegate = self;
[self.layer addAnimation:group forKey:@"animateCentreRightTransition"];
NSLog(@"Centre right %f", self.layer.position.x);
NSLog(@"%f", self.layer.position.y);
}

但是,当我的图层转换到新位置时,它的位置属性似乎保持不变?现在,当我旋转屏幕并设置位置坐标以适应横向模式时,结果不是我想要的,图层没有停留在我想要的位置。我在这里缺少什么?

最佳答案

动画不会更改图层的属性,因此一旦动画完成并从图层中删除,图层通常会移回其初始状态。

如果您希望图层在动画完成后保持其在动画中的最后位置,则需要在添加动画后立即将图层的位置显式设置为该点。例如:

[self.layer addAnimation:group forKey:@"animateCentreRightTransition"];
self.layer.position = somePoint;

关于iPhone CAKeyframeAnimation 不更新位置属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9113049/

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