简体   繁体   English

模态演示iOS 11

[英]Modal Presentation iOS 11

I am presenting a modal and it used to go "under" the status bar pre - iOS 11. 我提出了一个模态,它曾经在iOS 11之前的“状态栏”之下。

iOS 10: iOS 10: 在此输入图像描述

iOS 11: iOS 11: 在此输入图像描述

I would like to get it to display like it did in iOS 10 我想让它像在iOS 10中一样显示

All I was doing before was the following: 我之前做的就是以下内容:

let vc = ReferralsViewController()
vc.modalPresentationStyle = .overCurrentContext
self.present(vc, animated: true, completion: nil)

I had the same issue using Storyboard. 我使用Storyboard时遇到了同样的问题。 In my project the view was no longer being pinned to the superview. 在我的项目中,视图不再固定在superview上。 It looks like they have changed the top constraint to be of type Superview.Top.Margin instead of Superview.Top . 看起来他们已经改变了顶部约束为类型Superview.Top.Margin代替Superview.Top Though it could just be an individual case for me. 虽然它对我来说可能只是个案。

NOTE : When I did the drop down mine was still set to superview . 注意 :当我做下拉时,我的仍然设置为superview I just switched to another option and then back to superview . 我只是切换到另一个选项,然后回到superview I then need to change the constant value from 20 to 0. 然后我需要将常量值从20更改为0。

Update As to crashoverride777 comment, in order for this to work with iPhoneX you should pin your views to the new safe zones. 更新至于crashoverride777注释,为了使其与iPhoneX一起使用,您应该将视图固定到新的安全区域。

As you can see there is a gap at the top (the lighter part of the view). 如您所见,顶部有一个间隙(视图的较亮部分)。

在此输入图像描述

So I went on onto the constraint that connects that view to the top of the superview and set the second item from Superview.Top.Margin to Superview.Top . 所以我继续使用将该视图连接到superview顶部的约束,并将第二个项目从Superview.Top.MarginSuperview.Top

Finally change the second item from Superview.Top.Margin to Superview.Top . 最后将第二项从Superview.Top.Margin更改为Superview.Top

So firstly click the view that should be pinned to the top then go to Show the size inspector : 首先,单击应固定在顶部的视图,然后转到Show the size inspector

在此输入图像描述

So at the end it should like the below example: 所以最后它应该像下面的例子:

在此输入图像描述

The reason is because Apple deprecated Top/Bottom layout guide and replaced it with SafeArea. 原因是Apple弃用了Top / Bottom布局指南并将其替换为SafeArea。 You should pin your constraints to the SafeArea and not the Superview in most cases. 在大多数情况下,您应该将约束固定到SafeArea而不是Superview。 The currently accepted answer will most likely cause issues on an iPhoneX because everything is pinned to the superview instead of this SafeArea. 目前接受的答案很可能会导致iPhoneX出现问题,因为所有内容都固定在superview而非SafeArea上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM