简体   繁体   English

带有标签栏和导航栏的滚动视图自动布局

[英]Scrollview Autolayout with Tabbar and Navigationbar

I need to set constraints in uiscrollview in viewcontroller containing navigationbar and tabbar.I have placed a uiview(contentView) inside scrollview which is of same height as of scrollview.These are the things which I have set curently,我需要在包含导航栏和标签栏的视图控制器中的 uiview(contentView) 中设置约束。我在滚动视图中放置了一个 uiview(contentView),它与滚动视图的高度相同。这些是我目前设置的东西,

  1. set 4 constraints for scrollview(top,bottom,left,right) with constraints to margin unchecked which is 0 for all edges.为 scrollview(top,bottom,left,right) 设置 4 个约束,约束未选中边距,所有边缘均为 0。
  2. set 4 constraints for uiview(contentView) inside scrollview(top,bottom,left,right) with constraints to margin unchecked which is 0 for all edges.在 scrollview(top,bottom,left,right) 内为 uiview(contentView) 设置 4 个约束,约束未选中边距,所有边缘均为 0。
  3. set equal width and equal height for scrollview and UIView(contentView)为滚动视图和 UIView(contentView) 设置等宽和等高

output is displaying like this uiview(contentView) gets placed lower about 64 px (approx).This view should not place like this.Can anyone help me to solve this.输出显示像这样 uiview(contentView) 被放置在较低约 64 像素(大约)。这个视图不应该像这样放置。任何人都可以帮我解决这个问题。

Here is the project demo which I have worked and can be downloaded here这是我工作过的项目演示, 可以在这里下载

Select the scene and in the attributes inspector, uncheck: "Under Top Bars" and "Under Bottom Bars".选择场景并在属性检查器中取消选中:“Under Top Bars”和“Under Bottom Bars”。

在此处输入图片说明

Then in the storyboard make the scroll view start at the very top of the View Controller, where the navigation bar starts, and then the UIView, where the navigation Bar ends.然后在情节提要中使滚动视图从 View Controller 的最顶部开始,导航栏开始的地方,然后是 UIView,导航栏结束的地方。

Later, select the Scroll View and set the constraints as they come by default.稍后,选择 Scroll View 并设置默认情况下的约束。

在此处输入图片说明

I guess it's not the cleanest way to do it but I had the same issue and worked for me.我想这不是最干净的方法,但我遇到了同样的问题并且为我工作。

您可以尝试self.automaticallyAdjustsScrollViewInsets = false

The Tab Bar has to be set in the tree UNDER the scrollView, like this:标签栏必须在滚动视图下的树中设置,如下所示:

控制器树

Try this尝试这个

override func viewDidLoad() {
    self.edgesForExtendedLayout = UIRectEdge()
    self.extendedLayoutIncludesOpaqueBars = false

} }

我找到了解决方案,将父 ViewController 类设置为顶栏下方并禁用它并相应地更改了父级中的框架并将相同的属性和框架设置为子视图控制器修复了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM