如何在iOS 8中为自定义呈现的视图控制器处理调用(双高)状态栏的布局? [英] How to do layout to handle in-call (double-height) status bar for custom presented view controller in iOS 8?
问题描述
在iOS 7中,我能够处理自定义呈现视图控制器的布局,还可以通过添加约束来解释通话状态栏,其中呈现的视图控制器具有与呈现相同的中心和相同的宽度和高度查看控制器。这对于宽度和高度使用自动调整大小是首选,因为否则,当呼叫状态栏消失时,由于某种原因,呈现的视图控制器将保持从顶部向下推20点。
然而,在iOS 8中,这个技巧不再适用了。首先,我通过实验发现,呈现视图控制器似乎不一定在容器视图中,因此我无法将这些约束添加到容器视图中。 ( 我一直在玩查看内部演示控制器示例代码,但即使此代码也无法处理通话中状态正确吧。 (顺便说一句,我仍然试图处理新的 对我有用的是为 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 What worked for me was adding an observer for
这篇关于如何在iOS 8中为自定义呈现的视图控制器处理调用(双高)状态栏的布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
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
}
}
}
}
UIPresentationController
API, by the way.)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
}
}
}
}