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

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

问题描述

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



然而,在iOS 8中,这个技巧不再适用了。首先,我通过实验发现,呈现视图控制器似乎不一定在容器视图中,因此我无法将这些约束添加到容器视图中。 (示例代码: //developer.apple.com/videos/wwdc/2014/\">查看内部演示控制器2014 WWDC视频不会将呈现视图控制器放在那里。)似乎将所呈现的视图控制器填充使用自动布局或自动调整大小的容器视图可以工作,但我发现当呼叫状态栏消失时,容器视图本身可能会被按下20分(在iOS 7中不是这种情况)。 / p>

我一直在玩查看内部演示控制器示例代码,但即使此代码也无法处理通话中状态正确吧。 (顺便说一句,我仍然试图处理新的 UIPresentationController API。)

解决方案

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

  func willChangeStatusBarFrame(通知:NSNotification)
{
如果让userInfo = notification.userInfo
{
if let value = userInfo [UIApplicationStatusBarFrameUserInfoKey]为? 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
}
}
}
}


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.

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).

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.)

解决方案

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天全站免登陆