Ios 在卡巴斯基化结束时反弹
设置动画:Ios 在卡巴斯基化结束时反弹,ios,objective-c,cabasicanimation,Ios,Objective C,Cabasicanimation,设置动画: CABasicAnimation *noteAnimation = [CABasicAnimation animation]; noteAnimation.keyPath = @"position.x"; noteAnimation.byValue = [NSNumber numberWithFloat:CGRectGetWidth(self.view.frame) - 50]; noteAnimation.duration = 1.f; noteAnimation.fillMode
CABasicAnimation *noteAnimation = [CABasicAnimation animation];
noteAnimation.keyPath = @"position.x";
noteAnimation.byValue = [NSNumber numberWithFloat:CGRectGetWidth(self.view.frame) - 50];
noteAnimation.duration = 1.f;
noteAnimation.fillMode = kCAFillModeBoth;
noteAnimation.removedOnCompletion = NO;
noteAnimation.autoreverses = YES;
noteAnimation.repeatCount = HUGE;
noteAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[self.greenSquareView.layer addAnimation:noteAnimation forKey:@"noteAnimation"];
要暂停我使用的动作动画,请执行以下操作:
CFTimeInterval pausedTime = [view.layer convertTime:CACurrentMediaTime() fromLayer:nil];
view.layer.speed = 0.0;
view.layer.timeOffset = pausedTime;
但在本例中,视图停止反弹
完整的项目
你应该总是问一个问题。由于
speed
和timeOffset
都不是可设置动画的属性,我将尝试removeAllimations()
并将层的当前模型值设置为显示层的值(在本例中为位置)。你必须开始一个新的CATransaction
,并使用CATransaction禁用动画。setDisableActions(false)
,然后将位置与显示层同步,然后提交事务。我不想要动画speed
和timeOffset
(我在问题中添加了一些信息)。我使用此属性暂停动画。我尝试了你的方法-它不起作用(反弹复制的问题)。我下载了你的项目,它没有反弹就暂停了。首先:你在附加的gif上看到反弹了吗?(我从iphone上录制了这段视频)。我没有在模拟器中看到弹跳。但是在真实的设备(iPhone6,iOS10.1)上,这个“bug”重现了。是的,在gif上,我完全明白你的意思。下班后,我会尝试在真实的设备上复制。