以下代码用于将wantsLayer
设置为YES的NSButton。这是有效的,但是如果应用程序忙于处理背景中的某些内容,则旋转动画非常不稳定:
POPSpringAnimation *animation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerRotation];
animation.springBounciness = 8;
animation.springSpeed = 10;
animation.toValue = @(M_PI);
[self.myButton.layer pop_addAnimation:animation forKey:@"rotate"];
然后我将其更改为以下内容并且工作非常顺利:
CGAffineTransform transform = CGAffineTransformMakeRotation(-M_PI);
CABasicAnimation *thAnimation = [ CABasicAnimation animationWithKeyPath: @"transform" ];
thAnimation.duration = 0.2;
CATransform3D oldTrans = [self.myButton layer].transform;
thAnimation.fromValue = [ NSValue valueWithCATransform3D: oldTrans ];
CATransform3D newTrans = CATransform3DMakeAffineTransform (transform);
thAnimation.toValue = [ NSValue valueWithCATransform3D: newTrans ];
[[self.myButton layer] addAnimation: thAnimation forKey: @"rotate" ];
[[self.myButton layer] setAffineTransform: transform];
我仍然喜欢使用POPSpringAnimation。我注意到它直接使用引擎盖下的DisplayLink计时器。有没有办法让POP为我的仿射变换设置动画?
答案 0 :(得分:1)
好的,我发现了这个问题。在POPAnimator.m中,displaylinkCallback
方法正在执行此操作:
dispatch_async(dispatch_get_main_queue(), ^{
[(__bridge POPAnimator*)context render];
});
由于它在主线程上呈现,并且应用程序的主线程有时忙或被阻止,动画也会阻塞。我所要做的就是在POP上启用后台线程:
[POPAnimator setDisableBackgroundThread: NO];