我的动画可以在几个不同的类似视图上执行(在数组中管理),但是完成处理程序不接受参数。那么,我怎样才能知道在完成时间,我正在完成的动画?
下面它用来动画一个(几个) sectionViews的框架。当动画完成后,我需要能够向特定的sectionView发送通知。
NSLog(@"Animation started");
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:kAnimationDuration];
[[NSAnimationContext currentContext] setCompletionHandler:^{
[self doStuff];
NSLog(@"Animation complete - now we need to notify the correct sectionView");
}];
[[sectionView animator] setFrame:[self frameForSectionView:sectionView]];
[NSAnimationContext endGrouping];发布于 2017-02-01 20:42:37
只需在完成处理程序块中引用sectionView。如果它是实例变量、静态变量或全局变量,则在用当前值初始化的块外部创建一个局部变量,然后在块中引用该局部变量。
该块将捕获该值。
https://stackoverflow.com/questions/41988347
复制相似问题