我正在尝试使 StackView 内容可滚动。我插入了虚拟 UIImage 视图以尝试使其工作,但它不滚动。Stack 和 Scroll 视图已经连接到 IB。我错过了什么?
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)
}
}