UINavigationControllerの階層ごとにUINavigationBarの色を変える
こういう色分けしたサブカテゴリがあるとして、紫のをタップしたら次の階層は
こうなるようにしたかった。けれどただUINavigationBarのtintColorを変えたのでは、遷移アニメーションと関係なく色が切り替わってしまう。これはよろしくない。アニメーションと一緒にじわっと切り替わってほしい。
そこでCATransitionを使ってみた。UINavigationBarのカテゴリ。
#import <QuartzCore/QuartzCore.h> #import "RTDUINavigationBarAdditions.h" @implementation UINavigationBar (RTDUINavigationBarAdditions) -(void)setTintColor:(UIColor *)aColor animated:(BOOL)aBool { if (aBool) { CATransition *transition = [CATransition animation]; transition.type = kCATransitionFade; transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; transition.delegate = self; [self.layer addAnimation:transition forKey:nil]; } self.tintColor = aColor; } @end
これを遷移アニメーションと一緒に呼んでやる。…標準のiPodアプリとは微妙に違うような気がするけどまあいいや。