[英]“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.