Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

TransitionController for animating iOS view controller transitions w/o a controller stack

View TransitionController.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
//
// TransitionController.h
//
// Created by XJones on 11/25/11.
//
 
#import <UIKit/UIKit.h>
 
@interface TransitionController : UIViewController
 
@property (nonatomic, strong) UIView * containerView;
@property (nonatomic, strong) UIViewController * viewController;
 
- (id)initWithViewController:(UIViewController *)viewController;
- (void)transitionToViewController:(UIViewController *)viewController
withOptions:(UIViewAnimationOptions)options;
 
@end
View TransitionController.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
//
// TransitionController.m
//
// Created by XJones on 11/25/11.
//
 
#import "TransitionController.h"
 
@implementation TransitionController
 
@synthesize containerView = _containerView,
viewController = _viewController;
 
- (id)initWithViewController:(UIViewController *)viewController
{
if (self = [super init]) {
_viewController = viewController;
}
return self;
}
 
- (void)loadView
{
self.wantsFullScreenLayout = YES;
UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
self.view = view;
_containerView = [[UIView alloc] initWithFrame:view.bounds];
_containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[self.view addSubview:_containerView];
[_containerView addSubview:self.viewController.view];
}
 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return [self.viewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
 
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self.viewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
 
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[self.viewController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}
 
- (void)transitionToViewController:(UIViewController *)aViewController
withOptions:(UIViewAnimationOptions)options
{
aViewController.view.frame = self.containerView.bounds;
[UIView transitionWithView:self.containerView
duration:0.65f
options:options
animations:^{
[self.viewController.view removeFromSuperview];
[self.containerView addSubview:aViewController.view];
}
completion:^(BOOL finished){
self.viewController = aViewController;
}];
}
 
@end
View TransitionController.h
1 2 3 4 5 6 7 8 9 10 11 12 13
TransitionController
 
A UIViewController subclass that allows for easy transitions to new view controllers in any orientation with a specified transition options.
 
instance methods
 
- (void)initWithViewController:(UIViewController *)viewController
 
Initializes a new TransitionController displaying the specified viewController.
 
- (void)transitionToViewController:(UIViewController *)viewController withOptions:(UIViewAnimationOptions)options
 
Transitions to a new view controller with the specified options.

Thanks

Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.