2009-12-11 135 views
6

這可能嗎?我可以改變圖層的不透明度和位置(中心),但每當我嘗試更改大小或原點時,它都不起作用。使用核心動畫調整大小和移動UIView(CAKeyFrameAnimation)

CAAnimationGroup* anigroup = [CAAnimationGroup new]; 

    CGMutablePathRef thePath = CGPathCreateMutable(); 
    CGPathAddRect(thePath, NULL, CGRectMake(0,0, 320, 480)); 
    CGPathAddRect(thePath, NULL, CGRectMake(location.x - 16,location.y-24, 32, 48)); 
    CGPathAddRect(thePath, NULL, CGRectMake(190, 20, 32, 48)); 


    CAKeyframeAnimation* AniLoc = [CAKeyframeAnimation animationWithKeyPath:@"frame"]; 
    AniLoc.path = thePath; 
    AniLoc.keyTimes= [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f], 
              [NSNumber numberWithFloat:0.3f], 
              [NSNumber numberWithFloat:1.0f],nil]; 
    AniLoc.duration = 5; 

    CFRelease(thePath); 

    anigroup.animations = [NSArray arrayWithObjects:AniLoc,nil]; 
    anigroup.duration = 5; 

    [focusview.layer addAnimation:anigroup forKey:nil]; 

回答

10

你既可以改變動畫視圖或層的大小和位置,但你要做到這一點作爲一個動畫組,而不是由一系列矩形的創建路徑。

我提供了一個分組動畫同時收縮,並在我的答案here降低其不透明度沿着路徑移動的視圖的一個例子。這是通過使用用於CAKeyframeAnimation該視圖如下(僅動畫其位置)彎曲路徑,並且然後使用一個基本的動畫調整視圖的邊界的大小。您還可以在那裏使用CAKeyframeAnimation,併爲每個您想要的尺寸關鍵幀使用多個CGSize,確保在將它們放入NSArray的關鍵幀之前將它們包裝在NSValue中。

要一次動畫兩個屬性,我換了兩個動畫在CAAnimationGroup並應用到視圖的層。

+0

太棒了,這正是我一直在尋找的。謝謝! – ACBurk 2009-12-11 16:33:36