
我阅读并实现了Technical Q&A QA1673关于暂停层树中的所有动画,但我遇到了使用延迟参数的动画的问题.我可以暂停和恢复动画,但是当动画恢复时,任何与其相关的延迟的动画块似乎都会延迟图层树暂停的时间.因此,例如,如果其中一个块的延迟为1秒,并且图层树暂停3秒,则动画在恢复后会延迟4秒.我猜这与beginTime属性有关?任何帮助,将不胜感激.
// Pause and Resume methods,right from the technical Q&A- (voID)pauseAnimationsOnLayer:(CALayer *)layer{ CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil]; layer.speed = 0.0; layer.timeOffset = pausedTime;}- (voID)resumeAnimationsOnLayer:(CALayer *)layer{ CFTimeInterval pausedTime = [layer timeOffset]; layer.speed = 1.0; layer.timeOffset = 0.0; layer.beginTime = 0; CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime; layer.beginTime = timeSincePause;}// Chained animations- (voID)animateNextPopup{ [UIVIEw animateWithDuration:kRFPVictorySequenceStatePopupDuration animations:^{ [_currentStateImageVIEw setHIDden:NO]; [_currentStateImageVIEw settransform:CGAffinetransformIDentity]; } completion:^(BOol finished) { [UIVIEw animateWithDuration:kRFPVictorySequenceStateSlIDeOffDuration delay:kRFPVictorySequenceStateVoteDelay options:UIVIEwAnimationoptionCurveEaseInOut animations:^{ if (winnerIsDem) { [_currentStateImageVIEw setFrame:CGRectMake(-_currentStateImageVIEw.frame.size.wIDth,_currentStateImageVIEw.frame.origin.y,_currentStateImageVIEw.frame.size.wIDth,_currentStateImageVIEw.frame.size.height)]; } else { [_currentStateImageVIEw setFrame:CGRectMake(1024,_currentStateImageVIEw.frame.size.height)]; } } completion:^(BOol finished) { // Do some stuff } ]; } ];}解决方法 我建议采用不同的方法. 动画块很容易实现,但只有在您不需要对动画进行任何控制时才有用.
否则,您应该使用计时器并手动创建自己的动画.
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timerFired) userInfo:nil repeats:YES];- (voID)timerFired{ if (isPaused) { // Do nothing } else { // Animate }}- (IBAction)pauseTapped:(ID)sender{ if (isPaused) { isPaused = NO; } else { isPaused = YES; }} isPaused是一个控制动画状态的标志.
总结以上是内存溢出为你收集整理的ios – 使用延迟动画暂停CALayer动画全部内容,希望文章能够帮你解决ios – 使用延迟动画暂停CALayer动画所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)