0
我想讓StackView內容可以滾動。我插入了虛擬UIImage視圖來試圖讓它工作,但它不滾動。堆棧和滾動視圖已經連接到IB。我錯過了什麼?我不能讓UIScrollView與UIStackView一起工作
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var menuStackView: UIStackView!
@IBOutlet weak var menuScrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var itemImageView = UIImageView(image: UIImage(named: "splash2"))
itemImageView.contentMode = .ScaleAspectFit
self.menuStackView.addArrangedSubview(itemImageView)
itemImageView = UIImageView(image: UIImage(named: "splash2"))
itemImageView.contentMode = .ScaleAspectFit
self.menuStackView.addArrangedSubview(itemImageView)
itemImageView = UIImageView(image: UIImage(named: "splash2"))
itemImageView.contentMode = .ScaleAspectFit
self.menuStackView.addArrangedSubview(itemImageView)
itemImageView = UIImageView(image: UIImage(named: "splash2"))
itemImageView.contentMode = .ScaleAspectFit
self.menuStackView.addArrangedSubview(itemImageView)
itemImageView = UIImageView(image: UIImage(named: "splash2"))
itemImageView.contentMode = .ScaleAspectFit
self.menuStackView.addArrangedSubview(itemImageView)
itemImageView = UIImageView(image: UIImage(named: "splash2"))
itemImageView.contentMode = .ScaleAspectFit
self.menuStackView.addArrangedSubview(itemImageView)
itemImageView = UIImageView(image: UIImage(named: "splash2"))
itemImageView.contentMode = .ScaleAspectFit
self.menuStackView.addArrangedSubview(itemImageView)
itemImageView = UIImageView(image: UIImage(named: "splash2"))
itemImageView.contentMode = .ScaleAspectFit
self.menuStackView.addArrangedSubview(itemImageView)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
menuScrollView.contentSize = CGSize(width: menuStackView.frame.width, height: menuStackView.frame.height)
}
}