[OSX][iOS]アニメーションの種類(キーフレーム(Path)) | Cocoa練習帳

[OSX][iOS]アニメーションの種類(キーフレーム(Path))

今回はパスを設定する方法を紹介する。




- (CAKeyframeAnimation *)originAnimation
{
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
    animation.duration = 4.0;
    animation.path = self.heartPath;
    animation.calculationMode = kCAAnimationPaced;
    return animation;
}
 
- (CGMutablePathRef)heartPath
{
    if (! _heartPath) {
        NSRect  frame = self.mover.frame;
        _heartPath = CGPathCreateMutable();
        CGPathMoveToPoint(_heartPath, NULL, NSMinX(frame), NSMinY(frame));
        CGPathAddLineToPoint(_heartPath, NULL,
                             NSMinX(frame) - NSWidth(frame),
                             NSMinY(frame) + NSHeight(frame) * 0.85);
        CGPathAddLineToPoint(_heartPath, NULL,
                             NSMinX(frame),
                             NSMinY(frame) - NSHeight(frame) * 1.5);
        CGPathAddLineToPoint(_heartPath, NULL,
                             NSMinX(frame) + NSWidth(frame),
                             NSMinY(frame) + NSHeight(frame) * 0.85);
        CGPathAddLineToPoint(_heartPath, NULL,
                             NSMinX(frame),
                             NSMinY(frame));
        CGPathCloseSubpath(_heartPath);
    }
    return _heartPath;
}



前回のvaluesの代わりに、pathにCGPathRefを設定する。今回の場合、keyTimesは不要なので、無効にする為、calculationModeにkCAAnimationPacedを設定している。




関連情報
Core Animation for Max OS X and the iPhone



【Cocoa練習帳】
http://www.bitz.co.jp/weblog/

http://ameblo.jp/bitz/(ミラー・サイト)