2012-01-09 24 views
5

ここで私のコードはUIview 30pxをy = 10まで移動しますが、このアニメーションは機能しません。これはCAKeyframeAnimationを作成する私の最初の試みです。だから、誰でも私が正しくそれを書くのを助けることができます。また、私のオブジェクトを元の場所に戻ってくるのではなく、アニメーションが終了した場所に残しておきたい。CAKeyframeanimationは、パスに沿ってUIViewを移動します

CGMutablePathRef thePath = CGPathCreateMutable(); 
    CGPathAddRect(thePath, NULL, CGRectMake(self.logo.frame.origin.x, self.logo.frame.origin.y, self.logo.frame.size.width, self.logo.frame.size.height)); 
    CGPathAddRect(thePath, NULL, CGRectMake(self.logo.frame.origin.x, self.logo.frame.origin.y-30, self.logo.frame.size.width, self.logo.frame.size.height)); 
    CGPathAddRect(thePath, NULL, CGRectMake(self.logo.frame.origin.x, 100, self.logo.frame.size.width, self.logo.frame.size.height)); 


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

    CFRelease(thePath); 

    [self.logo.layer addAnimation:AniLoc forKey:nil]; 
+0

どのように「機能しない」のですか? – jrturton

+0

アニメーションは何も動かない –

答えて

1

私はあなたの方法が機能しない理由はかなりわからないんだけど、私は別の解決策を提案することができます。代わりにフレームを駆動する、あなたがUIViewのを移動する位置キーを変更することができ :

CGMutablePathRef thePath = CGPathCreateMutable(); 
    CGPathMoveToPoint(thePath, NULL, self.logo.frame.origin.x, self.logo.frame.origin.y); // initial point, notice the function 
    CGPathAddLineToPoint(thePath, NULL, self.logo.frame.origin.x - 30, self.logo.frame.origin.y); 
    CGPathAddLineToPoint(thePath, NULL, 100, self.logo.frame.origin.y); 

    CAKeyframeAnimation* AniLoc = [CAKeyframeAnimation animationWithKeyPath:@"position"]; // notice key change 

    // rest is the same 
    AniLoc.path = thePath; 
    AniLoc.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 
    AniLoc.keyTimes= [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f], 
         [NSNumber numberWithFloat:0.3f], 
         [NSNumber numberWithFloat:1.0f],nil]; 
    AniLoc.duration = 2.0; 

    CFRelease(thePath); 

    [self.logo.layer addAnimation:AniLoc forKey:nil]; 

私はこれがあなたを助け願っています。

+1

フレームは派生プロパティなので動作しません。フレームをアニメートする必要がある場合は、境界線と位置をアニメートします。 – alecail

関連する問題