2012-08-01 88 views
3

我正在爲我的卡片應用程序實現一些簡單的動畫。等到動畫塊在賽前完成

到目前爲止,一切工作都很順利,但在完成之前我只有一個更多的細節需要解決。

的方案是非常簡單的:前賽格瑞模態帶來了新的屏幕

三卡必須與動畫退出屏幕。

到目前爲止,他的動畫被執行並且新的視圖被加載,但是我沒有能夠解決的細節是「等到動畫完成之後才帶來新視圖」。

這是我怎麼做:用這種方法

- (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; 
     }   
    }];  
} 

正如我之前所說,一切正常,但模態窗口出現在動畫完成之前。

任何想法我失蹤?

回答

3

而是在prepareForSeque方法觸發動畫,你應該嘗試調用[self performExitAnimationWithCompletionBlock]當你想使用在最終的動畫完成塊[self performSegueWithIdentifier]方法手動啓動動畫過程,然後觸發塞克。

我會假設你的seque它當前連接到一個按鈕觸摸你的故事板。如果是這種情況,您將不得不在故事板中斷開連接。也許你可以通過連接到故事板上的一個看不見的按鈕讓它永遠不會被自動激活。

相反,寫按鈕的代碼如下所示:

-(void)btnStartSeque:(id)sender{ 

     //trigger animations 

     [self performExitAnimationWithCompletionBlock:^(BOOL finished){ 
     [self performSegueWithIdentifer:@"AddOptions" sender:self]; 
    }];  
} 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ 

    // 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; 
    }    
} 

的替代(?也許是更好的)解決方案,以得到你想要的是完全不使用塞克的功能,而是手動轉換屏幕。在這種情況下,請從故事板完全刪除seque。還要確保在storyboard中提供OptionsViewController的標識符。對導致動畫/轉換的動作執行以下代碼:

-(void)btnStartModalTransition:(id)sender{ 

     //trigger animations 

     [self performExitAnimationWithCompletionBlock:^(BOOL finished){ 

      //load the storyboard (sub in the name of your storyboard) 
      UIStoryBoard* storyBoard = [UIStoryBoard storyBoardWithName:@"MyStoryBoard" bundle:nil] 
      //load optionsviewcontroller from storyboard 
      OptionsViewController *controller = (OptionsViewController *)[storyBoard instantiateViewControllerWithIdentifier:@"OptionsViewControllerIdentifier"]; 
      UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller]; 

     controller.delegate = self; 
     [self presentModalViewController:navigationController animated:YES]; 
    }];  
} 
+0

嗨pdriegen,感謝您的回覆。你的建議改進了實施,但主要問題依然存在。 performExitAnimationWithCompletionBlock沒有完成,當segue進來。另外,我猜測,因爲我在按鈕方法中調用「AddOptions」,我可以將它從prepareForSegue中刪除嗎? 「如果([segue.identifier isEqualToString:@」AddOptions「])」不再需要我想。 – 2012-08-02 08:40:37

+0

@JuanGonzález:是的,我沒有注意到seque將不得不在故事板中進行調整,以免自動啓動。我還提供了一個替代解決方案,它不會在所有可能效果更好的情況下使用seques。請注意,我沒有真正測試過這些... – pdriegen 2012-08-02 13:09:40

+0

沒關係。你的回答給了我需要解決的方向。謝謝! – 2012-08-02 15:59:29