[OSX][iOS]Cocoa Animation(アニメーションの検索) | Cocoa練習帳

[OSX][iOS]Cocoa Animation(アニメーションの検索)

インタフェースから実装は予想できるが、やはり、確認したいので、アニメーションさせているNSImageViewのサブクラスを作成して、プロキシのメソッドが、どのように呼ばれているのか探っていみることにした。




以下が調査用のサブクラス。




#import <Cocoa/Cocoa.h>
@interface MyImageView : NSImageView
@end
 
#import "MyImageView.h"
 
@interface MyImageView ()
@end
 
@implementation MyImageView
- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
    }
    return self;
}
 
+ (id)defaultAnimationForKey:(NSString *)key
{
    DBGMSG(@"%s, key:%@", __func__, key);
    id result = [super defaultAnimationForKey:key];
    DBGMSG(@"%s, animation:%@", __func__, result);
    return result;
}
 
- (id)animationForKey:(NSString *)key
{
    DBGMSG(@"%s, key:%@", __func__, key);
    id  result = [super animationForKey:key];
    DBGMSG(@"%s, animation:%@", __func__, result);
    return result;
}
@end



そして、NSImageViewでインスタンスを生成していたところをMyImageViewに変更する。




self.mover = [[MyImageView alloc] initWithFrame:self.leftFramePosiotion];



以下がデバッグ出力。




2012-12-31 15:12:00.639 CocoaAnimation[2189:403] -[MyImageView animationForKey:], key:frameSize
2012-12-31 15:12:00.642 CocoaAnimation[2189:403] +[MyImageView defaultAnimationForKey:], key:frameSize
2012-12-31 15:12:00.644 CocoaAnimation[2189:403] +[MyImageView defaultAnimationForKey:], animation:
2012-12-31 15:12:00.645 CocoaAnimation[2189:403] -[MyImageView animationForKey:], animation:
2012-12-31 15:12:00.647 CocoaAnimation[2189:403] -[MyImageView animationForKey:], key:frameOrigin
2012-12-31 15:12:00.648 CocoaAnimation[2189:403] +[MyImageView defaultAnimationForKey:], key:frameOrigin
2012-12-31 15:12:00.649 CocoaAnimation[2189:403] +[MyImageView defaultAnimationForKey:], animation:
2012-12-31 15:12:00.650 CocoaAnimation[2189:403] -[MyImageView animationForKey:], animation:



-animationForKey:で検索したが見つからず、+defaultAnimationForKey:で検索して見つかったのが分かると思う。




これを独自に追加したアニメーションの場合だとどうなるだろうか?BaseViewの-moveで、フレームを設定しているのを透明度に変更。




2012-12-31 15:20:36.110 CocoaAnimation[2215:403] -[MyImageView animationForKey:], key:alphaValue
2012-12-31 15:20:36.114 CocoaAnimation[2215:403] -[MyImageView animationForKey:], animation:



独自に追加したアニメーションが見つかっている。




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



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

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