【发布时间】:2020-07-13 14:21:47
【问题描述】:
我尝试将 UIStackView 放置在 UIScrollView 中,并使用自动调整掩码 .flexibleWidth、.flexibleHeight -> 即水平/垂直拉伸以填充滚动视图,但如果我将其更改为带有前导/尾随/底部的自动布局代码,则堆栈视图不会出现/top 约束然后视图正确显示
toolbar.autoresizingMask = [.flexibleWidth, .flexibleHeight]
toolbar.backgroundColor = .clear
toolbar.axis = .horizontal
toolbar.distribution = .fill
toolbar.alignment = .fill
toolbar.spacing = 8
toolbarScroll.frame = bounds
toolbarScroll.autoresizingMask = [.flexibleHeight, .flexibleWidth]
toolbarScroll.showsHorizontalScrollIndicator = false
toolbarScroll.showsVerticalScrollIndicator = false
toolbarScroll.backgroundColor = UIColor.green
toolbarScroll.addSubview(toolbar)
这里的代码如果在 addSubview 之后添加,那么工具栏会显示在 toolbarScroll 中
toolbar.translatesAutoresizingMaskIntoConstraints = false
toolbar.leadingAnchor.constraint(equalTo: toolbarScroll.leadingAnchor).isActive = true
toolbar.trailingAnchor.constraint(equalTo: toolbarScroll.trailingAnchor).isActive = true
toolbar.bottomAnchor.constraint(equalTo: toolbarScroll.bottomAnchor).isActive = true
toolbar.topAnchor.constraint(equalTo: toolbarScroll.topAnchor).isActive = true
【问题讨论】:
标签: uiscrollview autolayout uikit uistackview autoresizingmask