lun*_*ner 3 animation block objective-c
我有几个动画块,所有动画块都遵循这种基本格式,具有不同的延迟,以便它们一个接一个地触发:
[UIView animateWithDuration:.85 delay:3 options:opts animations:[animations objectAtIndex:ww] completion:[completions objectAtIndex:ww]];
Run Code Online (Sandbox Code Playgroud)
选项只是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();
}];
Run Code Online (Sandbox Code Playgroud)
作为参考,动画非常简单,只需将图像从一个点移动到另一个点然后再移回.它崩溃的点[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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10858 次 |
| 最近记录: |