我有几个动画 block ,所有动画 block 都遵循这种具有不同延迟的基本格式,以便它们一个接一个地触发:
[UIView animateWithDuration:.85 delay:3 options:opts animations:[animations objectAtIndex:ww] completion:[completions objectAtIndex:ww]];
选项只是 UIViewAnimationOptionAutoreverse
在变量中以便于访问。
我希望在动画和完成之间有一个延迟,以便图像在返回原始位置之前在新位置停留一点点。我已经考虑过使用几个更简单的 animateWithDuration:animations:
block ,但我没有看到任何方法来延迟文档,除非我遗漏了什么。
@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();
}];
作为引用,动画非常简单,只需将图像从一个点移动到另一个点,然后再返回。它崩溃的地方是定义完成 block 的 [UIView animateWithDuration:.5
行,它在动画的第一部分运行后崩溃。
最佳答案
将另一个动画传递给完成怎么样?
已更新
我已将代码更新为我设置的示例中的确切工作代码。这是使用 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;
}
关于objective-c - objective-c ,动画 block ,动画和完成之间的延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8349282/