简体   繁体   中英

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

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

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. In your storyboard, select root view.

在此处输入图像描述

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

在此处输入图像描述

  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.

在此处输入图像描述

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)

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 : 在此处输入图像描述

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: 取消选中安全区域

Maybe someone came here with same question..

如果您正在使用情节提要,但您只想为特定视图禁用安全区域指南,您可以在右侧的大小检查器选项卡中通过禁用“安全区域布局指南”复选框来执行此操作。

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

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!

请务必为正在呈现的 VC 设置 modalPresentationStyle = .fullScreen -> 然后可能遵循其他答案以将其绑定到超级视图而不是安全区域

Try to config insetsLayoutMarginsFromSafeArea and contentInsetAdjustmentBehavior.

if #available(iOS 11.0, *) {
    scrollView.insetsLayoutMarginsFromSafeArea = false
    scrollView.contentInsetAdjustmentBehavior = .never
}

I have faced the same issue and tried all above solutions.
It killed couple of days, finally I found issue in my app ie, 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

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