[英]“presented view controller always full screen” not true for iOS 7 custom transitioning?
Apple文檔( 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。 已經有很多演示顯示“ presentedViewController”可以是我們想要的任何大小。 在這種情況下,Apple的文檔不正確嗎?
我相信蘋果仍然是正確的,盡管可能會引起誤解。 默認情況下它將全屏顯示,但是如果您提供自定義過渡委托,則可以對框架執行任何操作,等等。
蘋果全屏的意思是(我認為是在這種情況下),它的邊緣延伸到了設備的最大高度和最大寬度。 以前,它會受到諸如導航欄或可能添加的其他工具欄之類的限制,但是默認情況下,在iOS 7中,它們不再尊重它們。
但是,通過自定義過渡,您現在可以通過在過渡期間更改框架的大小來使較小的視圖控制器覆蓋另一個視圖控制器。 有關示例,請參見Teehan&Lax的出色過渡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是對的,但在解釋本方法的說明時可能並不完全透徹。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.