views:

18

answers:

0

I am trying to create a category for UINavigationController so I can put together a few custom animations. I came across this question and it got me started. I've come up with the following for a push function:

- (void)pushViewControllerMoveInFromBottom:(UIViewController *)viewController {
    [CATransaction begin];
    CATransition *transition;
    transition = [CATransition animation];
    transition.type = kCATransitionMoveIn;
    transition.subtype = kCATransitionFromBottom;
    transition.duration = 0.7;

    [CATransaction setValue:(id)kCFBooleanTrue
                     forKey:kCATransactionDisableActions];

    [[[[self.view subviews] objectAtIndex:0] layer] addAnimation:transition forKey:nil];
    [self  pushViewController:viewController animated:YES];
    [CATransaction commit];
}

I don't understand which view/layer is being accessed via the subview call. So if someone could help me understand that, that would be helpful. It seems to be effecting whatever view is about to come onto the screen.

But my main question is that I'm trying to create a pop that will "undo" the above function. For clarity sake, lets say I have two views, A and B. A is the first view that is shown on the screen. The function above, will move in B without pushing A out. Much like a modal view would. But the function below slides A back in over B, rather that sliding B up and leaving A in place.

- (void)popViewControllerMoveInFromTop {
    [CATransaction begin];
    CATransition *transition;
    transition = [CATransition animation];
    transition.type = kCATransitionMoveIn;
    transition.subtype = kCATransitionFromTop;
    transition.duration = 0.7;

    [CATransaction setValue:(id)kCFBooleanTrue
                     forKey:kCATransactionDisableActions];

    [[[[self.view subviews] objectAtIndex:0] layer] addAnimation:transition forKey:nil];
    [self  popViewControllerAnimated:YES];    
    [CATransaction commit];
}

I don't want to use a modal view and I would rather not use custom animation blocks to change the frame of the views.