5

我在 Storyboard 中设置了两个视图控制器,每个控制器都有一个操作按钮。我设置了两个segue:

  1. 从第一个视图控制器到第二个视图控制器:Modal、Flip Horizo​​ntal。
  2. 从第二个视图控制器到第一个视图控制器:Modal、Flip Horizo​​ntal。

一切正常,但我希望它可以单向翻转,现在它为两个视图控制器翻转相同的方向。

制作翻转翻转效果的最简单方法是什么?

4

3 回答 3

6

我遇到了同样的问题,希望找到解决方案。

我使用自定义 segue 来翻转回去的路。这是我的代码FlipLeftSegue

@implementation FlipLeftSegue
- (void)perform
{
    UIViewController *src = (UIViewController *) self.sourceViewController;
    UIViewController *dst = (UIViewController *) self.destinationViewController;    

    [UIView beginAnimations:@"LeftFlip" context:nil];
    [UIView setAnimationDuration:0.8];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:src.view.superview cache:YES];
    [UIView commitAnimations];

    [src presentViewController:dst animated:NO completion:nil];
}
@end

我发现这个解决方案的唯一问题viewDidAppear是动画开始时立即调用该方法。而对于普通的 segue,它是在动画之后调用的。

于 2012-05-23T14:49:42.343 回答
5

我建议不要创建 ViewController 的新演示文稿,而是访问第二个 ViewController 上的 presentingViewController 属性,然后在其上调用 -dismissViewControllerAnimated:completion:。像这样:

-(IBAction)someResponderToYourCancelButtonOrWhatever:(id)sender {
    // Do some stuff
    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
于 2013-04-10T05:51:13.090 回答
1

您最好在 NSZombie 的回答中使用此代码:

- (void)swapChildVCFrom:(UIViewController *)from to:(UIViewController *)to options:(enum UIViewAnimationOptions)options
{
    [self addChildViewController:to];
    [from willMoveToParentViewController:nil];

    // Adjust the new child view controller's view's frame
    // For example here just set it to fill the parent view
    to.view.frame = self.view.bounds;

    [self transitionFromViewController:from
                      toViewController:to
                              duration:1.0
                               options:options
                            animations:nil
                            completion:^(BOOL b)
                            {
                                [to didMoveToParentViewController:self];
                                [from.view removeFromSuperview];
                                [from removeFromParentViewController];
                            }];
}
于 2014-05-29T12:48:51.027 回答