Skip to content

@xjones /TransitionController.h
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
TransitionController for animating iOS view controller transitions w/o a controller stack
//
// 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
//
// 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
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.
@johndpope

Thanks

@danyalvarez

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.