Reputation: 4844
I have created two custom segue files and in both, I have overrode the perform
method. However, it seems that the custom segue only works when presenting the new UIViewController
, and the reverse one, does not animate just dismisses the source UIViewController
.
Reverse custom 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];
}
Thanks in advance!
Upvotes: 0
Views: 2353
Reputation: 6803
Segues add a new version of a view controller. When I was starting out I had some interesting problems with using segues to dismiss view controllers.
Instead of writing a custom segue, you should use a custom animation block in the view controller you are "dismissing to".
Upvotes: 1