如何在 iOS 8 中为自定义呈现的视图控制器进行布局以处理通话中(双高)状态栏? [英] How to do layout to handle in-call (double-height) status bar for custom presented view controller in iOS 8?

查看:9
本文介绍了如何在 iOS 8 中为自定义呈现的视图控制器进行布局以处理通话中(双高)状态栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 iOS 7 中,我能够处理自定义呈现的视图控制器的布局,以通过添加约束来处理通话中的状态栏,其中呈现的视图控制器具有与呈现相同的中心和相同的宽度和高度视图控制器.这比对宽度和高度使用自动调整大小更可取,因为否则,当通话中状态栏消失时,呈现的视图控制器会出于某种原因保持从顶部向下推 20 点.

In iOS 7, I was able to handle layout for a custom presented view controller to also account for the in-call status bar by adding constraints where the presented view controller has the same center and the same width and height as the presenting view controller. This was preferred to using auto-resizing for the width and height because, otherwise, when the in-call status bar goes away, the presented view controller would remain pushed down by 20 points from the top for some reason.

然而,在 iOS 8 中,这个技巧不再起作用.一方面,我通过实验发现呈现视图控制器似乎不一定在容器视图中,因此我无法将这些约束添加到容器视图中.(用于 "A Look Inside Presentation Controllers" 2014 WWDC video 没有将呈现视图控制器放在那里.)似乎填充了呈现的视图控制器使用自动布局或自动调整大小的容器视图可以工作,但我发现当通话中状态栏消失时,容器视图本身可能会保持向下推 20 个点(iOS 7 中不是这种情况).

In iOS 8, however, this trick doesn't work anymore. For one thing, I found through experimentation that the presenting view controller does not seem to necessarily be in the container view, so I can't add those constraints to the container view. (The sample code for the "A Look Inside Presentation Controllers" 2014 WWDC video does not put the presenting view controller in there.) It seems that having the presented view controller filling the container view using either auto-layout or auto-resizing would work, but I found that the container view itself may remain pushed down by 20 points when the in-call status bar disappears (which was not the case in iOS 7).

我一直在玩演示控制器内部一览"" 示例代码,但即使是此代码也无法正确处理通话中状态栏.(顺便说一下,我仍在尝试处理新的 UIPresentationController API.)

I've been playing around with the "A Look Inside Presentation Controllers" sample code, but even this code does not handle the in-call status bar correctly. (I'm still trying to get a handle on the new UIPresentationController API, by the way.)

推荐答案

对我有用的是为 UIApplicationWillChangeStatusBarFrameNotification 添加一个观察者,然后找到 transitionContext.containerView()并更新框架.我在查看调试时注意到 transitionContext.containerView() 框架在返回到正常状态栏高度时没有更新.

What worked for me was adding an observer for UIApplicationWillChangeStatusBarFrameNotification, then finding the transitionContext.containerView() and updating the frame. I noticed when view debugging that the transitionContext.containerView() frame wasn't updated when going back to the normal status bar height.

func willChangeStatusBarFrame(notification: NSNotification)
{
    if let userInfo = notification.userInfo
    {
        if let value = userInfo[UIApplicationStatusBarFrameUserInfoKey] as? NSValue
        {
            let statusBarFrame = value.CGRectValue()
            let transitionView = UIApplication.sharedApplication().delegate!.window!!.subviews.last! as UIView
            var frame = transitionView.frame
            frame.origin.y = statusBarFrame.height-20
            frame.size.height = UIScreen.mainScreen().bounds.height-frame.origin.y
            UIView.animateWithDuration(0.35) {
                transitionView.frame = frame
            }
        }
    }
}

这篇关于如何在 iOS 8 中为自定义呈现的视图控制器进行布局以处理通话中(双高)状态栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆