ios 7自定义转换不适用于导航控制器

时间:2013-09-25 22:53:20

标签: ios objective-c uinavigationcontroller ios7 transition

我正在测试新的iOS 7自定义转换API,但我在导航控制器的情况下遇到了一些麻烦。我现在尝试了一个非常基本的测试:

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    [transitionContext completeTransition:YES];
}

正如您所猜测的,除了完成没有动画的过渡之​​外,此代码不执行任何操作。 但问题是:如果它正常工作并显示/关闭控制器,我所看到的所有推送和弹出方法都是黑屏,好像[transitionContext completeTransition:YES]不起作用。

我已经正确设置了所有委托属性和委托方法,因为这个方法一直被调用(present,dismiss,push,pop)。

有人已经面临这个问题吗?

1 个答案:

答案 0 :(得分:3)

尝试更像这样的东西,我也遇到了麻烦,这有助于让它更有意义

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
{

    // 1. obtain state from the context
    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    CGRect finalFrame = [transitionContext finalFrameForViewController:toViewController];

    // 2. obtain the container view
    UIView *containerView = [transitionContext containerView];

    // 3. set initial state
    CGRect screenBounds = [[UIScreen mainScreen] bounds]; toViewController.view.frame =
    CGRectOffset(finalFrame, 0, screenBounds.size.height); 

    // 4. add the view
    [containerView addSubview:toViewController.view];

    // 5. animate
    NSTimeInterval duration = [self transitionDuration:transitionContext];

    [UIView animateWithDuration:duration animations:^{

        toViewController.view.frame = finalFrame; 

     } completion:^(BOOL finished) {

        // 6. inform the context of completion
        [transitionContext completeTransition:YES];

    }];
}

来源:http://www.raywenderlich.com/forums/viewtopic.php?f=37&t=8851