2014-03-24 17 views
0

蘋果文檔(https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/presentViewController:animated:completion :)說「在iPhone和iPod touch,所提出的觀點始終是全屏幕」。但在iOS 7中,有自定義視圖控制器轉換API。已經有很多演示顯示「presentsViewController」可以是我們想要的任何大小。蘋果的Doc在這種情況下不是真的嗎?「呈現視圖控制器始終全屏」不適用於iOS 7自定義轉換?

+0

蘋果的文檔都很好。我想,你只是忘記了,當你自定義,你可以做任何你想要的幀/邊界/邊緣的過渡,等... – Aaron

+0

默認情況下的一道風景iPhone 6+會適應全屏演示成一個模式的形式表,所以在技術上文檔是錯誤的。當您在縱向和橫向之間來回旋轉時,iPhone 6+甚至會在全屏和模式表單之間自動切換。 –

+0

@Aaron文檔有些誤導。是的,在說明所提供的視圖是「全屏」的情況下,您在技術上是正確的,但這對大多數API文檔消費者沒有幫助。 Apple文檔需要更新以清楚地表明呈現的視圖可以具有完全自定義的_appearance_,包括不出現全屏的外觀。這不僅僅是一個小小的風格問題:這是一個基本的可用性問題,它使得API突然變得更具吸引力和易於理解。 – Womble

回答

4

相信蘋果仍然是正確的,儘管也許是誤導。它會默認呈現全屏,但如果你提供一個自定義的過渡代表,你可以做任何你想要的框架,等等......

蘋果是什麼意思全屏(在這種情況下,我認爲),是它的邊緣延伸到設備的最大寬度&。以前它會通過之類的導航欄,或可能已添加其它工具欄的限制,但默認情況下在iOS的7,他們不會再尊重他們。

然而,隨着定製化,你現在可以有一個較小的視圖控制器覆蓋通過改變尺寸的轉變過程中它的框架另一個視圖控制器。見特安&鬆懈的真棒過渡API後這裏的一個例子:

http://www.teehanlax.com/blog/custom-uiviewcontroller-transitions/

這裏是爲視圖控制器上的幀設置爲這顯然不會是全屏的值-animateTransition方法。記下endFrame變量設置了線路:

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext { 
    // Grab the from and to view controllers from the context 
    UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 
    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 

    // Set our ending frame. We'll modify this later if we have to 
    CGRect endFrame = CGRectMake(80, 280, 160, 100); // <- frame is only 160 x 100 

    if (self.presenting) { 
     fromViewController.view.userInteractionEnabled = NO; 

     [transitionContext.containerView addSubview:fromViewController.view]; 
     [transitionContext.containerView addSubview:toViewController.view]; 

     CGRect startFrame = endFrame; 
     startFrame.origin.x += 320; 

     toViewController.view.frame = startFrame; 

     [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ 
      fromViewController.view.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed; 
      toViewController.view.frame = endFrame; 
     } completion:^(BOOL finished) { 
      [transitionContext completeTransition:YES]; 
     }]; 
    } 
    else { 
     toViewController.view.userInteractionEnabled = YES; 

     [transitionContext.containerView addSubview:toViewController.view]; 
     [transitionContext.containerView addSubview:fromViewController.view]; 

     endFrame.origin.x += 320; 

     [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ 
      toViewController.view.tintAdjustmentMode = UIViewTintAdjustmentModeAutomatic; 
      fromViewController.view.frame = endFrame; 
     } completion:^(BOOL finished) { 
      [transitionContext completeTransition:YES]; 
     }]; 
    } 
} 

因此,提供定製化的視圖控制器,當你從和過渡將您指定爲他們取的邊緣和/或幀。當你開始自定義轉換時,它們不會突然全屏顯示,所以Apple是正確的,但可能不完全透徹地解釋當前方法的描述。

相關問題