フィルタアニメーションのやり方がわからない...

テキストフィールドにフィルタをかけたるアニメーションを実装したいと思ったのですがなかなか思う通りにできません。みるくCocoaさんのサンプルにまさにコレ!というのがあったので早速試したのですが、デフォ0.25秒の動きが早すぎるのかどうしてもアニメーションしているようには見えませんでした。本家アップルののように、

CABasicAnimation *theAnimation =
  [CABasicAnimation animationWithKeyPath:@"filters.myGussian.inputRadius"];

theAnimation.duration            = 10;
theAnimation.fromValue           = [NSNumber numberWithFloat:5.0];
theAnimation.toValue             = [NSNumber numberWithFloat:0.0];
  
[[answerField layer] addAnimation:theAnimation forKey:@"filterAnimation"];

のように書き直しても動く気配なし。そもそもCore ImageとかCore Animationとか全然わかっていないのでコードの断片だけを拾い集めてきてもうまくいくはずもなく、アニメーションはあきらめて

if ([text wantsLayer])
{
  [text setWantsLayer:NO];
  [text setContentFilters:nil];
  return;
}
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur" keysAndValues:
                   kCIInputRadiusKey, [NSNumber numberWithFloat:2.5], nil];
[text setContentFilters:[NSArray arrayWithObject:filter]];
[text setWantsLayer:YES];

として、フィルタの適用をオン・オフだけするだけの実装にしてごまかして(実際これだけでも十分なんですが...)Core mage/Core Animation周りを勉強し直すことにしました。というわけで、これをポチ。

Core Animation for Max OS X and the iPhone: Creating Compelling Dynamic User Interfaces (Pragmatic Programmers) Core Animation for Max OS X and the iPhone: Creating Compelling Dynamic User Interfaces (Pragmatic Programmers)
Bill Dudney

Pragmatic Bookshelf 2008-10-15
売り上げランキング : 17174

Amazonで詳しく見る by G-Tools

この記事のトラックバックURL:

http://hippos-lab.com/blog/trackback/373

Comments