17

I don't know why the safe area covered my view on the iPhone X, simulator, but in xCode's view debug it seems ok. Is there any option to hide the safe area view or remove it? thanks in advance! Via the view debug I can see no view or nothing covered my view, it's all right, really strange.

I added this myView in the storyboard which turned on the safe area layout guide. I tried set additionalSafeAreaInsets.top additionalSafeAreaInsets.bottom to zero but it's not working.

Here is how I do the constraints:

func setupGroupBView() {
    self.groupBView = myView.create()
    self.view.addSubview(groupBView) 
    self.groupBView.snp.makeConstraints({ (make) in
        make.width.centerX.centerY.equalTo(self.view)
        make.height.equalTo(screenHeight)
    }) 
}

I tried set the myView's top, bottom to the controller's view.top view.bottom to -44, -34 but still it won't work.

please check this picture that shows the reality!

Please help!!!!

Anton Tropashko
  • 4,982
  • 3
  • 36
  • 58
Bi Brian
  • 179
  • 1
  • 1
  • 3

8 Answers8

20

You can disable safe area layout guide from storyboard for particular view controller.

Select View Controller -> File Inspector (first tab) -> Use safe area layout guides (uncheck the checkbox).

You can also change it programmatically in viewDidLoad().

view.insetsLayoutMarginsFromSafeArea = false

Hope this Helps!

Rajat Mishra
  • 767
  • 5
  • 14
  • Have you tried giving constraint through storyboard rather than programmatically? Can you please tell that is there any object of safeAreaInset in your view controller in storyboard? If so, try deleting it. – Rajat Mishra Mar 15 '18 at 02:36
19
  1. In your storyboard, select root view.

enter image description here

  1. In the Size inspector panel, uncheck Safe Area Layout Guide

enter image description here

  1. On the Add New Contratint panel, set all margins to 0 and uncheck Constrain to margins Please don't forget to click on Add xx Constraints button in the bottom.

enter image description here

Jason Jin
  • 1,465
  • 11
  • 20
5

If anyone is having this issue while using UIKit with SwiftUI in a UIViewRepresentable or UIViewControllerRepresentable, try adding this modifier to the view:

.ignoresSafeArea(.all)

Example with pseudo-code:

UIViewRepresentableView()
  .ignoresSafeArea(.all)
Nojze
  • 311
  • 4
  • 10
  • Does not work for iPhone X, iOS 15 – cora Apr 14 '22 at 16:17
  • This is helpful, but the toolbar is too small in this case. It hugs the bottom of the screen, as desired, but the content area does not rise above the safe area, as it does in the Mail app (for instance). – Casey Perkins Apr 26 '22 at 14:17
2

If you want create your own view without safeArea(Google sent me here with my question: "How to create view without safe area"), I found next easy solution: uncheck Safe Area

Maybe someone came here with same question..

1

I believe that you could change that from the storyboard also. just Select your view top constraint and then relate it with the superview. like that : enter image description here

1

If you are using storyboard, but you want to disable Safe area guides only for particular view, you can do it in Size inspector tab on the right, by disabling "Safe Area Layout Guide" checkbox.

locomotion
  • 1,498
  • 3
  • 10
  • 15
0

The truth is I have another viewController's view embed in my NavigationController, that viewController's view did not optimized for iPhone X, after optimized, everything's doing all right.

Thank you all guys!

Bi Brian
  • 179
  • 1
  • 1
  • 3
0

do be sure to set modalPresentationStyle = .fullScreen for the VC being presented -> then possibly follow other answers to tether to the superview rather than safe area

Anton Tropashko
  • 4,982
  • 3
  • 36
  • 58