2011-06-28 9 views
2

示例代碼是here隱式屬性動畫不適用於CAReplicatorLayer?

用隱式屬性動畫替換顯式屬性動畫後,動畫被打破。

明確動畫:

-(void)animate:(id)sender { 
    ... 
    //Transform Animation 
    animation = [CABasicAnimation animationWithKeyPath:@"transform"]; 
    animation.fromValue = [NSValue valueWithCATransform3D: CATransform3DIdentity]; 
    animation.toValue = [NSValue valueWithCATransform3D: t]; 
    animation.duration = 1.0; 
    animation.removedOnCompletion = NO; 
    animation.fillMode = kCAFillModeBoth; 
    [subLayer addAnimation:animation forKey:@"transform"]; 

    //Opacity Animation 
    animation = [CABasicAnimation animationWithKeyPath:@"opacity"]; 
    animation.fromValue = [NSNumber numberWithFloat:1.0]; 
    animation.toValue = [NSNumber numberWithFloat:0.0]; 
    animation.duration = 1.0; 
    animation.removedOnCompletion = NO; 
    animation.fillMode = kCAFillModeBoth; 
    [subLayer addAnimation:animation forKey:@"opacity"]; 
    ... 
} 

-(void)reset:(id)sender {  
    ... 
    //Transform Animation 
    animation = [CABasicAnimation animationWithKeyPath:@"transform"]; 
    animation.fromValue = [NSValue valueWithCATransform3D: t]; 
    animation.toValue = [NSValue valueWithCATransform3D: CATransform3DIdentity]; 
    animation.duration = 1.0; 
    animation.removedOnCompletion = NO; 
    animation.fillMode = kCAFillModeBoth; 
    [subLayer addAnimation:animation forKey:@"transform"]; 

    //Opacity Animation 
    animation = [CABasicAnimation animationWithKeyPath:@"opacity"]; 
    animation.fromValue = [NSNumber numberWithFloat:0.0]; 
    animation.toValue = [NSNumber numberWithFloat:1.0]; 
    animation.duration = 1.0; 
    animation.removedOnCompletion = NO; 
    animation.fillMode = kCAFillModeBoth; 
    [subLayer addAnimation:animation forKey:@"opacity"]; 

    ... 
} 

隱動畫:

-(void)animate:(id)sender { 
    ... 
    //Transform Animation 
    [CATransaction setAnimationDuration:1]; 
    subLayer.transform = t; 

    //Opacity Animation 
    [CATransaction setAnimationDuration:1]; 
    subLayer.opacity = 0; 
    ... 
} 

-(void)reset:(id)sender {  
    ... 
    //Transform Animation 
    [CATransaction setAnimationDuration:1]; 
    subLayer.transform = CATransform3DIdentity; 

    //Opacity Animation 
    [CATransaction setAnimationDuration:1]; 
    subLayer.opacity = 1;  
    ... 
} 

爲什麼?

回答

-2

您應該將CALayer的委託設置爲與視圖控制器在適當時間不同的視圖(沒有nitWithNibName:bundle:,awakeFromNib,viewDidLoad和viewWillAppear:animated),請看這裏:Does iPhone OS support implicit animation?

在我的機器上調用動畫時非常好用。

+0

顯然,我使用隱式事務。 – an0

+0

顯然,我錯了,確實發現了一個提示,但無法測試手頭沒有OSX的b/c。顯然,你不知道答案B/C你否則不會問。現在我已經研究了一些,並找到了適用於我的機器的答案。 –

+0

順便說一句,CATransaction的開始/提交併不會使動畫顯式化,只要不創建動畫並將其添加到圖層中,它仍然是隱式動畫。顯然,我應該加上:-) –

1

當您使用隱式動畫時,您不需要使用CATrasaction。 請小心,uikit禁用隱式動畫的圖層作爲UIView的根層。

+0

[CATransaction begin]; [CATransaction setValue:[NSNumber numberWithFloat:10.0f] forKey:kCATransactionAnimationDuration]; theLayer.zPosition = 200.0; theLayer.opacity = 0.0; [CATransaction commit]; – wihing

相關問題