2014-02-17 46 views
3

我正在實現我自己的自定義UIViewController轉換,並且當我向調試器輸出TO視圖控制器的幀時,我收到初始幀和最終幀的{{0, 0}, {0, 0}}。我認爲上下文中的方法應該顯示最終轉換之後的預期幀,以及轉換之前的初始幀。UIViewControllerContext initalFrameForViewController&finalFrameForViewController爲所有值顯示0

這是應該如何工作?

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

    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 

    CGRect initialToFrame = [transitionContext initialFrameForViewController:toVC]; 
    CGRect finalToFrame = [transitionContext finalFrameForViewController:toVC]; 
    NSLog(@"initialToFrame: %@, finalToFrame: %@", NSStringFromCGRect(initialToFrame), NSStringFromCGRect(finalToFrame)); 
} 

調試器表示: initialToFrame: {{0, 0}, {0, 0}}, finalToFrame: {{0, 0}, {0, 0}}


另外,調試器也呈現出以下警告。這是否會影響錯誤?

Presenting view controllers on detached view controllers is discouraged

+0

文檔說,當視圖尚未顯示在屏幕上或者在轉換過程中完全覆蓋時,這些方法可以返回'CGRectZero'。也許其中之一就是你的情況。 –

+0

我有同樣的問題,並且我沒有您收到的調試消息。 – bogardon

+0

set'modalPresentationStyle = UIModalPresentationFullScreen;' – bogardon

回答

1

你應該知道的第一件事是,有大約兩定做各種轉變:充分和非全屏,並且要求在非全屏轉變爲toVC.vew最後一幀只是沒有感。

在你沒有設置modalPresentationStyle或明確將其設置爲UIModalPresentationFullScreen(這是默認值)的UIKit知道toVC.view將覆蓋整個屏幕的情況下,這樣-finalFrameForViewController:toVC將返回正確的框架:主屏框架。

使用modalPresentationStyle = UIModalPresentationCustom你指定的過渡應該是非全屏,就是這樣:toVC.view將覆蓋部分fromVC.view(因此fromCV.view將保持在層次結構),其中toVC.view將覆蓋fromVC.view是你的決定這就是爲什麼-finalFrameForViewController:返回CGRectZero

CGRectZero告訴你的是:「嘿,夥伴,一個人留下,把這個觀點放在任何你想要的地方」。

入住此演示出更多的信息:http://es.slideshare.net/Split82/custom-uiviewcontroller-transitions

希望這有助於。

+0

那麼,initFrame呢? –