使用自定义segue关闭模态视图控制器

时间:2012-08-14 15:27:43

标签: objective-c uistoryboardsegue

我创建了两个自定义segue文件,在两者中,我已经覆盖了perform方法。但是,似乎自定义segue仅在呈现新UIViewController时有效,而反向自定义则不会动画仅仅关闭源UIViewController

反向自定义segue:

- (void)perform {
UIViewController *sourceViewController = self.sourceViewController;
    UIViewController *sourceTabBarController = sourceViewController.parentViewController.parentViewController;
    UIViewController *destinationViewController = self.destinationViewController;
    UIGraphicsBeginImageContext(destinationViewController.view.bounds.size);
        [destinationViewController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *destinationViewControllerImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

    UIImageView *destinationViewControllerImageView = [[UIImageView alloc] initWithImage:destinationViewControllerImage];
    destinationViewControllerImageView.userInteractionEnabled = YES;
    destinationViewControllerImageView.frame = CGRectMake(0.0f, 0.0f, CGRectGetWidth(destinationViewController.view.frame), CGRectGetHeight(destinationViewController.view.frame));

[destinationViewController.view insertSubview:destinationViewControllerImageView atIndex:1];

// Add animations
    [UIView animateWithDuration:0.4f
                          delay:0.0f
                        options:UIViewAnimationOptionCurveEaseIn
                     animations:^{
                         destinationViewControllerImageView.center = CGPointMake(-CGRectGetWidth(destinationViewControllerImageView.frame) / 2, -(CGRectGetHeight(destinationViewControllerImageView.frame) / 2));
                     }
                     completion:nil];

    [sourceViewController dismissViewControllerAnimated:NO completion:nil];
}

提前致谢!

1 个答案:

答案 0 :(得分:1)

Segues添加了一个新版本的视图控制器。当我开始时,我有一些有趣的问题,使用segues来解除视图控制器。

您应该在视图控制器中使用自定义动画块,而不是编写自定义segue。