简体   繁体   English

自动布局视图层次结构

[英]Auto Layout View Hierarchy

I need to display the layout I have in the picture in my app. 我需要在我的应用程序中显示图片中的布局。

The view hierarchy is: 视图层次结构是:

  • scroll view (scrollEnabled = true) 滚动视图(scrollEnabled = true)
    • image view 影像检视
    • label 标签
    • webview (scrollEnabled = false) webview(scrollEnabled = false)
    • table view (scrollEnabled = false, max amount of rows = 6) 表格视图(scrollEnabled = false,最大行数= 6)

The web view height is dynamically changed by it's delegate webViewDidFinishLoad. Web视图的高度由其委托webViewDidFinishLoad动态更改。

func webViewDidFinishLoad(webView: UIWebView) {
    webView.sizeToFit()
} 

How can I set up the auto layout to move the table view below the web view? 如何设置自动布局以将表格视图移动到Web视图下方?

所需的布局

First of all you need to add containerView in scrollView and then add subViews to containerView. 首先,您需要在scrollView中添加containerView,然后将subViews添加到containerView。

Below I've displayed the hierarchy you need to follow for displaying content in UIScrollView and the constraints you need to set. 下面,我显示了在UIScrollView中显示内容时需要遵循的层次结构以及需要设置的约束。

scroll View (constraints :- leading,trailing,top,bottom) 滚动视图(约束:-前导,尾随,顶部,底部)

Container View (constraints :- leading,trailing,top,bottom,widthsEqually to View,heightsEqually to View or height = 1000) 容器视图(约束:-前导,尾随,顶部,底部,宽度等于视图,高度等于视图或高度= 1000)

NOTE : If all subViews has specific height then there is no need to give height to ContainerView. 注意:如果所有子视图都有特定的高度,则无需为ContainerView赋予高度。

UIImageView (constraints :- leading,trailing,top,verticalSpacing,height) UIImageView(约束:-前导,尾随,顶部,verticalSpacing,高度)

UILabel (constraints :- leading,trailing,top,verticalSpacing,height) UILabel(约束:-前导,尾随,顶部,verticalSpacing,高度)

UIWebView (constraints :- leading,trailing,top,verticalSpacing,height>=0) UIWebView(约束:-前导,尾随,顶部,verticalSpacing,高度> = 0)

UITableView (constraints :- leading,trailing,top,Bottom) UITableView(约束:-前导,尾随,顶部,底部)

NOTE: give height to tableView if required. 注意:如果需要,请给tableView高度。 You will need to make changes in height constraint of UIWebView programmatically at run time based on your requirement. 您将需要根据需要在运行时以编程方式更改UIWebView的高度限制。

For more reference please refer links below: 有关更多参考,请参考以下链接:

http://spin.atomicobject.com/2014/03/05/uiscrollview-autolayout-ios/ http://blog.surecase.eu/working-with-uiscrollview-in-storyboard-using-autolayout/ http://makeapppie.com/2014/12/11/swift-swift-using-uiscrollview-with-autolayout/ http://spin.atomicobject.com/2014/03/05/uiscrollview-autolayout-ios/ http://blog.surecase.eu/working-with-uiscrollview-in-storyboard-using-autolayout/ http:// makeapppie.com/2014/12/11/swift-swift-using-uiscrollview-with-autolayout/

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

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