【问题标题】:"presented view controller always full screen" not true for iOS 7 custom transitioning?“呈现的视图控制器总是全屏”不适用于 iOS 7 自定义转换?
【发布时间】:2014-03-24 17:14:21
【问题描述】:

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 的 Doc 不是真的吗?

【问题讨论】:

  • Apple 的文档很好。我认为您只是忘记了,当您自定义过渡时,您可以使用框架/边界/边缘等做任何您想做的事情......
  • 默认情况下,横向 iPhone 6+ 会将全屏演示文稿调整为模态表单,因此从技术上讲,文档是错误的。当您在纵向和横向之间来回旋转时,iPhone 6+ 甚至会自动在全屏和模态表单之间切换。
  • @Aaron 文档有些误导。是的,您说呈现的视图是“全屏”在技术上是正确的,但这对大多数 API 文档的使用者来说没有帮助。 Apple 文档需要更新以清楚地表明呈现的视图可以具有完全自定义的外观,包括不全屏显示的外观。这不仅仅是风格的小问题:它是一个基本的可用性问题,它使 API 突然变得更具吸引力和易于理解。

标签: ios ios7 presentviewcontroller


【解决方案1】:

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

Apple 所说的全屏(在这种情况下,我认为)是指它的边缘延伸到设备的最大高度和宽度。以前它会受到可能已添加的导航栏或其他工具栏之类的限制,但在 iOS 7 中默认情况下它们不再尊重它们。

但是,使用自定义过渡,您现在可以通过在过渡期间更改其框架的大小来让较小的视图控制器覆盖另一个视图控制器。有关示例,请参阅 Teehan & Lax 的精彩转换 API 帖子:

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

这是 -animateTransition 方法,用于将 to 视图控制器上的框架设置为一个显然不会全屏显示的值。注意设置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];
        }];
    }
}

因此,当提供自定义转换时,您转换 fromto 的视图控制器将具有您为它们指定的任何边缘和/或框架。当您开始自定义转换时,它们不会突然变成全屏,所以 Apple 是对的,但它对当前方法描述的解释可能并不完全。

【讨论】:

    猜你喜欢
    • 2013-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-08
    相关资源
    最近更新 更多