I have tried embedding it, but my stack view is dynamic and my app is also changing orientations time to time. I have segment control at the end of the view. I have also tried googling it but had no luck. thanks in advance.
我试过嵌入它,但我的堆栈视图是动态的,我的应用程序也在不断改变方向。我在视图的末尾有段控制。我也试过谷歌搜索但没有运气。提前致谢。
So far I have done:
到目前为止我做了:
In view did load:
在视图中加载:
mainStackView.axis = UILayoutConstraintAxis.Vertical
mainStackView.spacing = 3
scrollView.frame = self.view.bounds
scrollView.addSubview(mainStackView)
view.addSubview(scrollView)
In view did layout:
在视图中做了布局:
override func viewDidLayoutSubviews()
{
super.viewDidLayoutSubviews()
let top = topLayoutGuide.length
let bottom = bottomLayoutGuide.length
self.mainStackView.frame = CGRect(x: 0, y: top, width: view.frame.width, height: view.frame.height - top - bottom).insetBy(dx: 10, dy: 10)
dispatch_async(dispatch_get_main_queue())
{
self.scrollView.frame = self.view.bounds
self.scrollView.contentSize = CGSize(width: self.view.bounds.width, height: self.segmentedControl.frame.origin.y + self.segmentedControl.frame.height + 50)
}
print(scrollView.contentSize)
}
1 个解决方案
#1
2
You need to set the height constraint of segment control.
您需要设置段控制的高度约束。
For Example:
segmentedControl.heightAnchor.constraintEqualToConstant(50).active = true
More over, you can Add Empty bottom view to avoid stack view's must fill mechanism. This will show you desired view output.
此外,您可以添加空底部视图以避免堆栈视图的必须填充机制。这将显示所需的视图输出。
var bottomView = UIView(frame: CGRectZero)
stackView.addArrangedSubview(bottomView)
#1
2
You need to set the height constraint of segment control.
您需要设置段控制的高度约束。
For Example:
segmentedControl.heightAnchor.constraintEqualToConstant(50).active = true
More over, you can Add Empty bottom view to avoid stack view's must fill mechanism. This will show you desired view output.
此外,您可以添加空底部视图以避免堆栈视图的必须填充机制。这将显示所需的视图输出。
var bottomView = UIView(frame: CGRectZero)
stackView.addArrangedSubview(bottomView)