我正在爲我的卡片應用程序實現一些簡單的動畫。等到動畫塊在賽前完成
到目前爲止,一切工作都很順利,但在完成之前我只有一個更多的細節需要解決。
的方案是非常簡單的:前賽格瑞模態帶來了新的屏幕
三卡必須與動畫退出屏幕。
到目前爲止,他的動畫被執行並且新的視圖被加載,但是我沒有能夠解決的細節是「等到動畫完成之後才帶來新視圖」。
這是我怎麼做:用這種方法
- (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之前包裹動畫中的SEGUE代碼
1)設置退出動畫「VC
- (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;
}
}];
}
正如我之前所說,一切正常,但模態窗口出現在動畫完成之前。
任何想法我失蹤?
嗨pdriegen,感謝您的回覆。你的建議改進了實施,但主要問題依然存在。 performExitAnimationWithCompletionBlock沒有完成,當segue進來。另外,我猜測,因爲我在按鈕方法中調用「AddOptions」,我可以將它從prepareForSegue中刪除嗎? 「如果([segue.identifier isEqualToString:@」AddOptions「])」不再需要我想。 – 2012-08-02 08:40:37
@JuanGonzález:是的,我沒有注意到seque將不得不在故事板中進行調整,以免自動啓動。我還提供了一個替代解決方案,它不會在所有可能效果更好的情況下使用seques。請注意,我沒有真正測試過這些... – pdriegen 2012-08-02 13:09:40
沒關係。你的回答給了我需要解決的方向。謝謝! – 2012-08-02 15:59:29