1

The native push transition shows the source view, and the transition over to the destination view seamlessly.

The modal transition shows the destination view overlaying the source view from the bottom.

I'd like a modal transition that works with the navigation controller.

So far I have this:

CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
    anim.duration = .2;
    anim.autoreverses = NO;
    anim.removedOnCompletion = YES;

    anim.fromValue = [NSNumber numberWithInt:sourceViewController.view.frame.size.height];
    anim.toValue = [NSNumber numberWithInt:0];

    [sourceViewController.navigationController.view.layer addAnimation:anim
                                                                 forKey:kCATransition];

    [sourceViewController.navigationController pushViewController:destinationController animated:NO];

This is in the -perform method in my segue subclass. The problem with this is that the navigation controller push is done almost immediately, and while the transition takes place, nothing of the source view is displayed. I want it to look as if it's overlaying.

I thought it might be possible to take a screenshot using Core Graphics and having that as a superview of the destination view, but I couldn't get it to work properly.

I also tried using one of the UIView animation methods like so:

[sourceViewController.view addSubview:destinationController.view];
    [destinationController.view setFrame:sourceViewController.view.window.frame];
    [destinationController.view setTransform:CGAffineTransformMakeTranslation(0, sourceViewController.view.frame.size.height)];
    [destinationController.view setAlpha:1.0];

    [UIView animateWithDuration:1.3
                          delay:0.0
                        options:UIViewAnimationOptionTransitionNone
                     animations:^{
                         [destinationController.view setTransform:CGAffineTransformMakeTranslation(0, 0)];
                         [destinationController.view setAlpha:1.0];

                     }
                     completion:^(BOOL finished){
                         [destinationController.view removeFromSuperview];
                         [sourceViewController.navigationController pushViewController:destinationController animated:NO];

                     }];

But again, there's an issue with this: the navigation bar isn't displayed until the view controller is actually pushed onto the navigation stack. So there's a sort of "jump" at the end of the animation when the navigation bar is suddenly displayed.

So what are my options with this?

4

1 回答 1

0

我通过创建源视图的图像并对其进行转换来解决这个问题。

此外,应该注意的是,“flash”在 ios 7 上不存在,因此不需要太多自定义代码。

于 2013-10-11T09:52:56.967 回答