我正在为我的卡片应用程序实现一些简单的动画。
到目前为止一切都很好,但在我可以说它完成之前,我还有一个细节需要修复。
场景非常简单:
在 segue 模态显示新屏幕之前,三张卡片必须以动画形式退出屏幕。
到目前为止,他的动画被执行并加载了新视图,但我无法解决的细节是“等到动画完成后再引入新视图”。
这就是我的做法:
1) 使用此方法设置退出动画
- (void)performExitAnimationWithCompletionBlock:(void (^)(BOOL))block
{
[UIView animateWithDuration:0.1f
delay:0.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^
{
self.optionOneFront.center = self.optionOneBack.center = self.optionTwoFront.center;
self.optionOneFront.transform = self.optionOneBack.transform = self.optionTwoFront.transform;
self.optionThreeFront.center = self.optionThreeBack.center = self.optionTwoFront.center;
self.optionThreeFront.transform = self.optionThreeBack.transform = self.optionTwoFront.transform;
}
completion:^(BOOL finished)
{
CGPoint point = CGPointMake(self.optionTwoFront.center.x, self.view.frame.size.height * -2.0f);
[UIView animateWithDuration:1.0f
delay:0.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^
{
self.optionOneFront.center = point;
self.optionOneBack.center = point;
self.optionTwoFront.center = point;
self.optionTwoBack.center = point;
self.optionThreeFront.center = point;
self.optionThreeBack.center = point;
}
completion:block];
}];
}
2)尝试在呈现“AddOptions”VC之前将segue代码包装在动画中
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
[self performExitAnimationWithCompletionBlock:^(BOOL finished)
{
// Executes the following "if" statement if the user wants to add new options
if ([segue.identifier isEqualToString:@"AddOptions"])
{
UINavigationController *navigationController = segue.destinationViewController;
OptionsViewController *controller = (OptionsViewController *)navigationController.topViewController;
controller.delegate = self;
}
}];
}
正如我之前所说,一切正常,但模式窗口在动画完成之前出现。
知道我缺少什么吗?