View is tethered to the safe area margin top rather than superview, how would I tether to the superview top?
Asked Answered
B

10

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

Bushwhacker answered 14/3, 2018 at 13:12 Comment(5)
ClipsToBounds? Layer.masksToBounds?Fulcrum
One possible issue is that your navigationBar is not transparent. Can you tryout making it transparent: https://mcmap.net/q/156868/-transparent-ios-navigation-bar.Tabbie
isn't the controller embedded in something?Hewitt
so while running the app you are getting the spaces at the top and bottom?Durkin
@Durkin yes, but it should not been there lolBushwhacker
J
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

Junior answered 18/8, 2020 at 4:19 Comment(0)
N
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!

Nonparous answered 14/3, 2018 at 19:56 Comment(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.Nonparous
I
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)
Indoor answered 8/9, 2021 at 10:32 Comment(2)
Does not work for iPhone X, iOS 15Greyhound
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).Taishataisho
L
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

Lissome answered 4/6, 2020 at 8:16 Comment(0)
G
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..

Genvieve answered 6/6, 2020 at 10:23 Comment(0)
M
2

Try to config insetsLayoutMarginsFromSafeArea and contentInsetAdjustmentBehavior.

if #available(iOS 11.0, *) {
    scrollView.insetsLayoutMarginsFromSafeArea = false
    scrollView.contentInsetAdjustmentBehavior = .never
}
Melvinamelvyn answered 20/6, 2022 at 6:33 Comment(0)
M
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.

Marin answered 2/7, 2020 at 9:2 Comment(0)
B
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!

Bushwhacker answered 15/3, 2018 at 7:8 Comment(0)
P
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

Polestar answered 9/9, 2021 at 13:33 Comment(0)
O
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

Operon answered 20/1, 2023 at 5:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.