我真的很困惑为什么这段代码在10.6和10.7上正常工作,但在10.8没有动画,不透明度值立即改变。 Self是NSView的子类。
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:0.5]
forKey:kCATransactionAnimationDuration];
self.layer.opacity = 1.0;
self.labelFilename.layer.opacity = 1.0;
self.labelDate.layer.opacity = 1.0;
[CATransaction commit];
相反,此代码无法在10.6上制作动画,但在10.7和10.8
上工作正常CABasicAnimation *theAnimation;
theAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
theAnimation.duration = 0.5;
theAnimation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut];
theAnimation.toValue=[NSNumber numberWithFloat:1.0];
theAnimation.removedOnCompletion = NO;
theAnimation.fillMode = kCAFillModeForwards;
[self.layer addAnimation:theAnimation forKey:@"fadeUp"];
[self.labelFilename.layer addAnimation:theAnimation forKey:@"fadeUpName"];
[self.labelDate.layer addAnimation:theAnimation forKey:@"fadeUpDate"];
答案 0 :(得分:0)
我通过添加显式动画让我的动画重新开始工作,如下所示:
// added explicit animation
CABasicAnimation *animOut = [CABasicAnimation animationWithKeyPath:@"transform"];
CATransform3D transform = CATransform3DMakeRotation(pi,0,1,0);
transform = CATransform3DScale(transform, scaleFactor, scaleFactor, 1.0f);
[animOut setFromValue:[NSValue valueWithCATransform3D:CATransform3DIdentity]];
[animOut setToValue:[NSValue valueWithCATransform3D:transform]];
[animOut setDuration:0.3f];
[[goingImageView layer] addAnimation:animOut forKey:nil];
// implicit animation code that worked before 10.8
[[goingImageView layer] setTransform:transform];