28

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!!!!

5
  • 1
    ClipsToBounds? Layer.masksToBounds? Commented Mar 14, 2018 at 13:20
  • One possible issue is that your navigationBar is not transparent. Can you tryout making it transparent: stackoverflow.com/a/25846056/3883492.
    – dvp.petrov
    Commented Mar 14, 2018 at 13:24
  • isn't the controller embedded in something? Commented Mar 14, 2018 at 13:26
  • so while running the app you are getting the spaces at the top and bottom?
    – Scriptable
    Commented Mar 14, 2018 at 13:30
  • @Scriptable yes, but it should not been there lol
    – Bi Brian
    Commented Mar 15, 2018 at 2:26

10 Answers 10

27
  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

22

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!

1
  • 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. Commented Mar 15, 2018 at 2:36
13

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)
2
  • Does not work for iPhone X, iOS 15
    – cora
    Commented Apr 14, 2022 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). Commented Apr 26, 2022 at 14:17
3

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

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

2

Try to config insetsLayoutMarginsFromSafeArea and contentInsetAdjustmentBehavior.

if #available(iOS 11.0, *) {
    scrollView.insetsLayoutMarginsFromSafeArea = false
    scrollView.contentInsetAdjustmentBehavior = .never
}
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.

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!

0
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

0

I have faced the same issue and tried all above solutions.
It killed couple of days, finally I found issue in my app i.e, we are adding view controllers as subviews to root view controller and they enabled in viewDidAppear

guard let TabBarVC = self.storyboard?.instantiateViewController(withIdentifier: "MainTabController") as? MainTabController else {return}
addChild(TabBarVC)
TabBarVC.view.translatesAutoresizingMaskIntoConstraints = false

I removed TabBarVC.view.translatesAutoresizingMaskIntoConstraints = false Then above solutions started working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.