Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save alanjrogers/671924 to your computer and use it in GitHub Desktop.

Select an option

Save alanjrogers/671924 to your computer and use it in GitHub Desktop.

Revisions

  1. Alan Rogers created this gist Nov 11, 2010.
    38 changes: 38 additions & 0 deletions UINavigationController+CustomTransitionAnimation.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    - (void)loadViewController:(UIViewController*)viewController withTransition:(AJRNavigationControllerTransition)transition
    {
    // This currently only works for a landscape only App.
    // Needs to check orientation as nav controller view isn't rotated.
    NSString* subtype = kCATransitionFromBottom;

    switch (transition)
    {
    case AJRNavigationControllerTransition_FromLeft:
    {
    subtype = ([self interfaceOrientation] == UIInterfaceOrientationLandscapeLeft) ? kCATransitionFromTop : kCATransitionFromBottom;
    break;
    }
    case AJRNavigationControllerTransition_FromRight:
    {
    subtype = ([self interfaceOrientation] == UIInterfaceOrientationLandscapeRight) ? kCATransitionFromTop : kCATransitionFromBottom;
    break;
    }
    default:
    break;
    }

    CATransition *animation = [CATransition animation];
    [animation setDuration:0.25];
    [animation setType:kCATransitionPush];
    [animation setSubtype:subtype];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

    [[self.navigationController.view layer] addAnimation:animation forKey:@"SwitchToView1"];

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.25];

    [UIView setAnimationBeginsFromCurrentState:YES];
    [self.navigationController pushViewController:viewController animated:NO];

    [UIView commitAnimations];
    }