Modal Presentation iOS 11

Viewed 1417

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

iOS 10: enter image description here

iOS 11: enter image description here

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)
2 Answers

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

enter image description here

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:

enter image description here

So at the end it should like the below example:

enter image description here

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.

Related