前回までは SelectionHistoryLayer という CALayer のサブクラスを作り、これを SelectionHandler と呼ぶ範囲選択クラスでこの管理を行っていた。しかしただでさえコード量の多い肥大化ぎみのクラス SelectionHandler に CALayer 関連の処理が入るとメンテナンスがやりづらい。そこで新規にクラスを作り、SHE(Selection History Epose)に関する主要処理の責務をそこに持たせることにした。そのクラスが SelectionHistoryLayeManager。中身はこんな感じ。
@interface SelectionHistoryLayerManager : NSObject {
CALayer* _baseLayer;
id _delegate;
BOOL _endAfterAnimation;
}
@property (nonatomic, assign) id delegate;
- (void)addLayerToView:(NSView*)view currentRect:(NSRect)currentRect;
- (void)animateStart:(NSRect)rect;
- (void)animateSelect:(NSRect)rect;
- (void)animateCancel:(NSRect)rect;
@end SHE 発動時に addLayerToView:currentRect: が呼ばれ、この時に SelectionHistory(履歴管理モデル)から履歴の矩形を取得して CALayerを生成する。そして animate* 系メソッドでアニメーションの制御が行われる。デリゲートはアニメーションが終わった時に SelectionHandler をコールバックするのに使う(SHEから通常モードへ復帰させる)。


Responses
Leave a Response