2012-08-10 82 views
0

我很困惑为什么这段代码在10.6和10.7上工作正常,但在10.8上没有动画,并且不透明度值立即改变。 Self是一个NSView子类。图层不透明度的隐式动画在Mountain Lion上不生成动画

[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

我有一个非常类似的问题。你有没有设法弄清楚是什么造成了这种情况? – Martin 2012-09-03 06:21:24

+0

我在10.8上有与CAAnimation类似的问题和其他问题(例如http://stackoverflow.com/questions/13307632/nsimageview-layer-not-updating-before-during-animation)。在这个问题上的任何进展? – thumbsup 2012-11-09 13:37:04

回答

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];