我有几个动画块,所有动画块都遵循这种基本格式,具有不同的延迟,以便它们一个接一个地触发:
[UIView animateWithDuration:.85 delay:3 options:opts animations:[animations objectAtIndex:ww] completion:[completions objectAtIndex:ww]];
变量中的选项只是UIViewAnimationOptionAutoreverse
,便于访问。
我希望在动画和完成之间有一个延迟,以便图像在返回到原始图像之前保持一点位置。我考虑过使用几个更简单的animateWithDuration:animations:
块,但我没有看到任何方法来解决文档中的延迟,除非我遗漏了一些东西。
@ Paul.s这里是我用你给我的代码:
void (^completion)(void) = ^{
[UIView animateWithDuration:.5
delay:5
options:UIViewAnimationCurveLinear
animations:[completions objectAtIndex:ww]
completion:^(BOOL finished) {}];
};
// Call your existing animation with the new completion block
[UIView animateWithDuration:.5
delay:1
options:UIViewAnimationCurveLinear
animations:[animations objectAtIndex:ww]
completion:^(BOOL finished) {
completion();
}];
作为参考,动画非常简单,只需将图像从一个点移动到另一个点然后再移回。它崩溃的点是[UIView animateWithDuration:.5
行,其中定义了完成块,并且在动画的第一部分运行后崩溃。
答案 0 :(得分:6)
如何将另一个动画传递给完成?
<强>更新强>
我已将代码更新为我设置的示例中的确切工作代码。这是使用Empty Application
模板
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
CGRect startFrame = CGRectMake(0, 0, 100, 100);
UIView *view = [[UIView alloc] initWithFrame:startFrame];
view.backgroundColor = [UIColor greenColor];
[self.window addSubview:view];
// Set up your completion animation in a block
void (^completion)(void) = ^{
[UIView animateWithDuration:0.5f
delay:0.5f
options:UIViewAnimationCurveLinear
animations:^{
view.frame = startFrame;
}
completion:nil];
};
// Call your existing animation with the new completion block
[UIView animateWithDuration:4
delay:1
options:UIViewAnimationCurveLinear
animations:^{
view.frame = CGRectMake(200, 200, 10, 10);
}
completion:^(BOOL finished) {
completion();
}];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}