2012-08-01 85 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