5
我試圖嵌入它,但我的堆棧視圖是動態的,我的應用程序也在不時變化方向。我在視圖結尾處有段控制。 我也嘗試了谷歌搜索,但沒有運氣。提前致謝。如何以編程方式在滾動視圖中嵌入堆棧視圖
到目前爲止,我已經做了:
鑑於沒有負載:
mainStackView.axis = UILayoutConstraintAxis.Vertical
mainStackView.spacing = 3
scrollView.frame = self.view.bounds
scrollView.addSubview(mainStackView)
view.addSubview(scrollView)
鑑於沒有佈局:
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)
}
很好。這正是我正在尋找的東西。 – shafi