2013-09-25 79 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