2016-01-22 63 views
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) 
    } 

回答

2

你需要設置分段控制的高度約束。

例如:

segmentedControl.heightAnchor.constraintEqualToConstant(50).active = true 

更多了,你可以添加空底視圖,以避免堆棧視圖的必須填寫機制。這會顯示你想要的視圖輸出。

 var bottomView = UIView(frame: CGRectZero) 
     stackView.addArrangedSubview(bottomView) 
+0

很好。這正是我正在尋找的東西。 – shafi

相關問題