Created
July 19, 2013 08:10
-
-
Save ricobeck/6037526 to your computer and use it in GitHub Desktop.
Embedded View Controllers Segue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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