"呈现视图控制器始终全屏"不适用于iOS 7自定义转换?

时间:2014-03-24 17:14:22

标签: ios ios7 presentviewcontroller

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。已经有很多演示显示了" presentsViewController"可以是我们想要的任何尺寸。在这种情况下Apple的Doc是不是真的?

1 个答案:

答案 0 :(得分:4)

我相信苹果仍然是正确的,尽管可能会产生误导。默认情况下它将全屏显示,但如果您提供自定义转换委托,则可以对框架执行任何操作,等等...

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是正确的,但可能不完全彻底解释当前方法的描述。