简体   繁体   中英

Modal Presentation iOS 11

I am presenting a modal and it used to go "under" the status bar pre - iOS 11.

iOS 10: 在此输入图像描述

iOS 11: 在此输入图像描述

I would like to get it to display like it did in 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. In my project the view was no longer being pinned to the superview. It looks like they have changed the top constraint to be of type Superview.Top.Margin instead of 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 . I just switched to another option and then back to superview . I then need to change the constant value from 20 to 0.

Update As to crashoverride777 comment, in order for this to work with iPhoneX you should pin your views to the new safe zones.

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 .

Finally change the second item from Superview.Top.Margin to Superview.Top .

So firstly click the view that should be pinned to the top then go to 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. You should pin your constraints to the SafeArea and not the Superview in most cases. The currently accepted answer will most likely cause issues on an iPhoneX because everything is pinned to the superview instead of this SafeArea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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