閱讀演示文稿位置暫停時是否存在問題?我想暫停並恢復CALayer
。一旦CALayer
暫停,我想用它當前的顯示位置更新圖層的位置。 當我嘗試這樣做時,一旦恢復圖層,圖層會輕微閃爍。圖層暫停時更新CALayer位置是否存在問題?
這是我使用的暫停和恢復CALayer
(根據蘋果提供的Technical Q&A QA1673)的代碼:
CFTimeInterval pausedTime;
void pauseLayer(CALayer *layer)
{
pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
layer.speed = 0.0;
layer.timeOffset = pausedTime;
layer.beginTime = 0;
// layer.position = ((CALayer*)[layer presentationLayer]).position;
}
void resumeLayer(CALayer *layer)
{
layer.speed = 1.0;
layer.timeOffset = 0.0;
layer.beginTime = 0.0;
CFTimeInterval _elapsedTimeSincePaused = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
layer.beginTime = _elapsedTimeSincePaused;
}
如果我取消在pauseLayer
的layer.position = ((CALayer*)[layer presentationLayer]).position;
,層閃爍一次,我打電話resumeLayer
。
這是我的動畫代碼:
- (void) startAnimation:(id)sender
{
layer10Animation = [CABasicAnimation animationWithKeyPath:@"position.x"];
layer10Animation.duration = 1;
layer10Animation.toValue = [NSNumber numberWithInt:300];
layer10Animation.fromValue = [NSNumber numberWithInt:20];
layer10Animation.repeatCount = 100;
layer10Animation.autoreverses = YES;
[layer10 addAnimation:layer10Animation forKey:nil];
}
問候
你是什麼意思的忽悠做?圖層是否消失然後突然出現,或者它是否與相對於暫停位置的偏移繼續? – MiguelB 2011-07-19 16:18:47
圖層消失,然後突然重新出現。 – haroldcampbell 2011-10-05 14:23:38