Skip to content

Instantly share code, notes, and snippets.

@stephsharp
Last active October 28, 2015 10:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephsharp/9104411 to your computer and use it in GitHub Desktop.
Save stephsharp/9104411 to your computer and use it in GitHub Desktop.
Embed segue for iOS 6 & 7 (using constraints to pin edges of subview to container view)
//
// EmbedSegue.h
// Created by Stephanie Sharp on 20/02/14.
//
#import <UIKit/UIKit.h>
@interface EmbedSegue : UIStoryboardSegue
@property (nonatomic) UIView *containerView;
@property (nonatomic) CATransition *transition;
@end
//
// EmbedSegue.m
// Created by Stephanie Sharp on 20/02/14.
//
#import "EmbedSegue.h"
@implementation EmbedSegue
- (void)perform
{
if (self.transition) {
[self.containerView.layer addAnimation:self.transition forKey:kCATransition];
}
UIView * subview = [self.destinationViewController view];
subview.translatesAutoresizingMaskIntoConstraints = NO;
[self.sourceViewController addChildViewController:self.destinationViewController];
[self.containerView addSubview:subview];
[self.destinationViewController didMoveToParentViewController:self.sourceViewController];
NSDictionary * views = NSDictionaryOfVariableBindings(subview);
[self.containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[subview]|"
options:0
metrics:nil
views:views]];
[self.containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[subview]|"
options:0
metrics:nil
views:views]];
}
- (UIView *)containerView
{
if (!_containerView) {
_containerView = [self.sourceViewController view];
}
return _containerView;
}
@end
@xareelee
Copy link

Could this gist be released under MIT or Apache 2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment