我CABasicAnimation在视图中无休止地循环重复图像块:
a = [CABasicAnimation animationWithKeyPath:@"position"];
a.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionLinear];
a.fromValue = [NSValue valueWithCGPoint:CGPointMake(0, 0)];
a.toValue = [NSValue valueWithCGPoint:CGPointMake(image.size.width, 0)];
a.repeatCount = HUGE_VALF;
a.duration = 15.0;
[a retain];
Run Code Online (Sandbox Code Playgroud)
我已尝试按照技术问答QA1673中的描述"暂停并恢复"图层动画.
当应用程序进入后台时,动画将从图层中删除.为了补偿我听UIApplicationDidEnterBackgroundNotification,打电话stopAnimation和回应UIApplicationWillEnterForegroundNotification电话startAnimation.
- (void)startAnimation
{
if ([[self.layer animationKeys] count] == 0)
[self.layer addAnimation:a forKey:@"position"];
CFTimeInterval pausedTime = [self.layer timeOffset];
self.layer.speed = 1.0;
self.layer.timeOffset = 0.0;
self.layer.beginTime = 0.0;
CFTimeInterval timeSincePause =
[self.layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
self.layer.beginTime = timeSincePause;
}
- …Run Code Online (Sandbox Code Playgroud) 当我的应用程序退出后台时动画停止了.这是正常的.但我想从当前状态重新启动我的动画.如果没有我到处偷拍,我怎么做到这一点.
[UIView animateWithDuration:60 delay:0 options:(UIViewAnimationOptionCurveLinear |UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState) animations:^{
[bg setFrame:CGRectMake(0, 0, 1378, 1005)];
} completion:nil];
Run Code Online (Sandbox Code Playgroud)
我尝试在动画前放置一个设置框架,但这只是让它快速捕捉.
[bg setFrame:CGRectMake(0, 0, 1378, 1005)];
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?