Skip to content

Instantly share code, notes, and snippets.

@dbanksdesign
Created March 4, 2014 20:49
Show Gist options
  • Save dbanksdesign/9355328 to your computer and use it in GitHub Desktop.
Save dbanksdesign/9355328 to your computer and use it in GitHub Desktop.
//
// PvlseFromBottomSegue.m
// Pvlse
//
// Created by Daniel Banks on 2/9/14.
// Copyright (c) 2014 Pvlse. All rights reserved.
//
#import "PvlseFromBottomSegue.h"
#import "PvlseNavigationController.h"
@implementation PvlseFromBottomSegue
UIViewController *sourceViewController;
UIViewController *destinationViewController;
PvlseNavigationController *navViewController;
PvlseCheckInViewController *checkInViewController;
BOOL showing; // Stores if we are showing the check in view controller or hiding it
- (id)initWithIdentifier:(NSString *)identifier source:(UIViewController *)source destination:(UIViewController *)destination
{
self = [super initWithIdentifier:identifier source:source destination:destination];
if (self) {
// Custom initialization
}
return self;
}
// Performs the segue
-(void)perform
{
[self setUpControllers];
[self addViews];
[self setUpInitialState];
[self performAnimation];
}
- (void)setUpControllers
{
sourceViewController = (UIViewController *) self.sourceViewController;
destinationViewController = (UIViewController *) self.destinationViewController;
if ([sourceViewController class] == [PvlseCheckInViewController class]) {
navViewController = self.destinationViewController;
checkInViewController = (PvlseCheckInViewController *)self.sourceViewController;
showing = NO;
} else {
navViewController = (PvlseNavigationController *)sourceViewController.navigationController;
checkInViewController = (PvlseCheckInViewController *)self.destinationViewController;
showing = YES;
}
}
- (void)addViews
{
if (showing) {
[navViewController.view addSubview:checkInViewController.view];
[checkInViewController.view setFrame:navViewController.view.window.frame];
}
}
- (void)setUpInitialState
{
if (showing) {
// Place the check in view off screen
[checkInViewController.view setTransform:CGAffineTransformMakeTranslation(0, navViewController.view.frame.size.height)];
} else {
// [navViewController setNeedsStatusBarAppearanceUpdate];
}
}
- (void)performAnimation
{
[UIView animateWithDuration:0.35
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self finishedState];
}
completion:^(BOOL finished){
[self finishedAnimation];
}];
}
- (void)finishedState
{
if (showing) {
[checkInViewController.view setTransform:CGAffineTransformMakeTranslation(0, 0)];
} else {
[checkInViewController.view setTransform:CGAffineTransformMakeTranslation(0, navViewController.view.frame.size.height)];
}
}
- (void)finishedAnimation
{
if (showing) {
navViewController.checkInViewController = checkInViewController;
} else {
// Remove the view and remove the reference to the view controller
[checkInViewController.view removeFromSuperview];
}
[navViewController.topViewController setNeedsStatusBarAppearanceUpdate];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment