(良いタイトルが思い浮かばなかったので、長くなりました。。)
UIViewのAnimation処理でbeginAnimations:contextを使う方法で、
contextに任意のユーザ情報を渡すやり方です。
実際にbeginAnimations:contextは
+ (void)beginAnimations:(NSString *)animationID context:(void *)context
とcontextはvoid*型になっているので何でも渡せるようになっています。
以下は、contextを用いてユーザ情報を渡すSampleです。
// beginAnimations:context sample
- (void)animationStart {
NSDictionary *userInfo = @{@"key":@"val"};
[UIView beginAnimations:@"animation" context:(__bridge_retained void*)(userInfo)];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.27f];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
/* animation処理 */
[UIView commitAnimations];
}
次にAnimationが終了した際に呼ばれるメソッドの中身で、実際にcontextを受け取り解釈します。
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
NSDictionary *contextObj = (__bridge_transfer NSDictionary*)context;
NSLog(@"%@", contextObj[@"key"]);
}
実行結果
val
勘違いし易いのが(私も最初はそうでした)、beginAnimationsはグラフィックスコンテキストではありません。
上述の通り、アニメーションのデリゲートメソッドで受け取り、その後の条件判定用にユーザが好きに指定するものです。
間違ってる点等あれば、こちらでご指摘か、同じ記事を管理blogにも載せてますので、そちらにお願い致します。