トップ «前の日記(2012-12-20) 最新 次の日記(2013-01-01)» 編集

Cocoa練習帳

iOS/iPhone/iPad/watchOS/tvOS/MacOSX/Android プログラミング, Objective-C, Cocoa, Swiftなど

2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|09|10|11|12|
2024|01|02|

2012-12-31 [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:

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

_ 【Cocoa練習帳】

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

トップ «前の日記(2012-12-20) 最新 次の日記(2013-01-01)» 編集