3

我正在为我的卡片应用程序实现一些简单的动画。

到目前为止一切都很好,但在我可以说它完成之前,我还有一个细节需要修复。

场景非常简单:

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

正如我之前所说,一切正常,但模式窗口在动画完成之前出现。

知道我缺少什么吗?

4

1 回答 1

3

与其在方法中触发动画,不如在想要开始动画过程时prepareForSeque尝试调用,然后在最终动画的完成块中使用方法手动触发序列。[self performExitAnimationWithCompletionBlock][self performSegueWithIdentifier]

我假设您的序列当前连接到故事板中的按钮触摸。如果是这种情况,您将不得不在情节提要中断开它。也许你可以通过连接到故事板上的一个不可见按钮来保持序列的活力,这样它就永远不会被自动触发。

相反,像这样编写按钮代码:

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

获得您想要的功能的另一种(也许更好?)解决方案是根本不使用序列,而是手动转换屏幕。在这种情况下,从情节提要中完全删除序列。还要确保在情节提要中提供 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];
     }];    
}
于 2012-08-01T13:28:19.233 回答