2013-09-25 80 views
1

我正在测试新的iOS 7自定义转换API,但我在导航控制器的情况下有一些麻烦。我想一个非常基本的测试与此时刻:ios 7自定义转换不适用于导航控制器

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

正如你猜到了,这个代码什么也不做,除了完成与没有动画的过渡。 但是这里有个问题:如果它现在正常工作/关闭一个控制器,所有我看到的推送和弹出方法都是黑屏,就好像[transitionContext completeTransition:YES]没有工作。

我已经正确设置了所有的委托属性和委托方法,因为此方法一直被调用(存在,解雇,推送,弹出)。

有人已经遇到过这个问题吗?

+0

你的意思'[transitionContext completeTransition:YES]' ? – gWiz

+0

是的,thx我编辑。 – Yaman

回答

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

+1

此行'[containerView addSubview:toViewController.view];'使我的代码工作。看起来,我们总是需要将目标视图添加到容器视图,即使我们为动画使用快照视图。 Thx指引我正确的方向。 – Yaman