Skip to content

Instantly share code, notes, and snippets.

@ricobeck
Created July 19, 2013 08:10
Show Gist options
  • Save ricobeck/6037526 to your computer and use it in GitHub Desktop.
Save ricobeck/6037526 to your computer and use it in GitHub Desktop.
Embedded View Controllers Segue
//
// KFEmbeddedContainerSegue.h
//
// Created by Rico Becker on 18.07.13.
// Copyright (c) 2013 KF Interactive. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface KFEmbeddedContainerSegue : UIStoryboardSegue
@property (nonatomic) BOOL animate;
@end
//
// KFEmbeddedContainerSegue.m
//
// Created by Rico Becker on 18.07.13.
// Copyright (c) 2013 KF Interactive. All rights reserved.
//
#import "KFEmbeddedContainerSegue.h"
@implementation KFEmbeddedContainerSegue
- (void)perform
{
UIViewController *sourceViewController = (UIViewController *) self.sourceViewController;
UIViewController *destinationViewController = (UIViewController *) self.destinationViewController;
destinationViewController.view.center = sourceViewController.view.center;
destinationViewController.view.transform = sourceViewController.view.transform;
destinationViewController.view.bounds = sourceViewController.view.bounds;
UIViewController *parentViewController = [sourceViewController parentViewController];
UIView *containerView = [sourceViewController.view superview];
if (self.animate)
{
[parentViewController addChildViewController:destinationViewController];
[destinationViewController willMoveToParentViewController:parentViewController];
destinationViewController.view.alpha = .0f;
[containerView addSubview:destinationViewController.view];
[destinationViewController didMoveToParentViewController:parentViewController];
[UIView animateWithDuration:1.0f animations:^
{
destinationViewController.view.alpha = 1.0f;
sourceViewController.view.alpha = .0f;
}
completion:^(BOOL finished)
{
if (finished)
{
[sourceViewController.view removeFromSuperview];
[sourceViewController removeFromParentViewController];
}
}];
}
else
{
[sourceViewController.view removeFromSuperview];
[sourceViewController removeFromParentViewController];
[parentViewController addChildViewController:destinationViewController];
[destinationViewController willMoveToParentViewController:parentViewController];
[containerView addSubview:destinationViewController.view];
[destinationViewController didMoveToParentViewController:parentViewController];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment