下面的代码用于将NSButton设置为YES的wantsLayer
。但是,如果应用程序忙于处理背景中的某些内容,则旋转动画非常不稳定:
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计时器。有什么办法让流行音乐代替我的仿射变换吗?
发布于 2014-12-25 10:59:48
好吧我找到问题了。M.m中的displaylinkCallback
方法是这样做的:
dispatch_async(dispatch_get_main_queue(), ^{
[(__bridge POPAnimator*)context render];
});
因为它在主线程上呈现,并且应用程序的主线程有时很忙或被阻塞,所以动画也会阻塞。我所要做的就是启用POP上的后台线程:
[POPAnimator setDisableBackgroundThread: NO];
https://stackoverflow.com/questions/27607777
复制相似问题