0

我真的很困惑为什么这段代码在 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"];
4

1 回答 1

0

我通过添加显式动画让我的动画在 10.8 上恢复工作,如下所示:

// 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];
于 2012-11-09T13:41:21.897 回答