簡體   English   中英

動畫期間未調用CALayer setPosition

[英]CALayer setPosition not called during animation

我有一個自定義的CALayer ,我正在使用CAAnimationGroup進行動畫處理,以遵循路徑並在與該路徑的切線處旋轉:

   // Create the animation path
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;

//Setting Endpoint of the animation
CGRect contentBounds = [self contentBounds];
self.boatLayer.bounds = contentBounds;
CGPoint endPoint = CGPointMake(contentBounds.size.width - 150, contentBounds.size.height - 150);

CGMutablePathRef curvedPath = CGPathCreateMutable();
CGPathMoveToPoint(curvedPath, NULL, startPosition.x, startPosition.y);
CGPathAddCurveToPoint(curvedPath, NULL, endPoint.x, 0, endPoint.x, 0, endPoint.x, endPoint.y);
pathAnimation.path = curvedPath;

pathAnimation.duration = 10.0;
pathAnimation.rotationMode = kCAAnimationRotateAuto;
pathAnimation.delegate = self;

// Create an animation group of all the animations
CAAnimationGroup *animationGroup = [[[CAAnimationGroup alloc] init] autorelease];
animationGroup.animations = [NSArray arrayWithObjects:pathAnimation, nil];
animationGroup.duration = 10.0;
animationGroup.removedOnCompletion = NO;

// Add the animations group to the layer (this starts the animation at the next refresh cycle)
[testLayer addAnimation:animationGroup forKey:@"animation"];

我需要能夠跟蹤沿着路徑前進的圖層的位置和旋轉的變化。 我已經覆蓋了setPositionsetTransform (調用super setPositionsuper setTranform ),然后記錄了它們的值。 這些值似乎都沒有在動畫期間設置。

在動畫時,如何從CALayer類本身中獲取位置和旋轉更新?

核心動畫不能那樣工作

抱歉。 那不是核心動畫的工作方式。 將動畫添加到圖層時,它不會更改該圖層的模型。 僅介紹。

配置動畫后,動畫在完成時不會自行刪除

yourAnimation.fillMode = kCAFillModeForwards;
tourAnimation.removedOnCompletion = NO;

您實際上是在屏幕上顯示的內容與該層的模型之間造成不一致。 例如,如果您有一個像這樣動畫的按鈕,您將對其“不再響應觸摸器”或更有趣的“響應來自其“舊”位置的觸摸”感到非常驚訝/生氣。

半解決方案

根據您實際需要更新的頻率和頻率,可以在動畫過程中定期檢查presentationLayer的值,也可以在屏幕變化時使用CADisplayLink運行一些代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM