我有一组嵌套的
我阅读并实施了Technical Q&A QA1673关于暂停层树中所有动画的内容,但我遇到了一个使用延迟参数的动画问题。我可以正常地暂停和恢复动画,但是当动画恢复时,任何具有延迟的动画块似乎都会将其延迟延长与层树暂停的时间相同的时间量。因此,例如,如果其中一个块具有1秒的延迟,并且层树被暂停了3秒,则动画在恢复后延迟4秒。我猜这与
UIView
动画(在给定时间内有2或3个级别),我希望能够暂停和恢复。其中一些动画使用-animateWithDuration:animations:completion:
,而另一些使用-animateWithDuration:delay:options:animations:completion:
以延迟执行动画块。我阅读并实施了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.origin.y,
_currentStateImageView.frame.size.width,
_currentStateImageView.frame.size.height)];
}
}
completion:^(BOOL finished) {
// Do some stuff
}
];
}
];
}