我在viewDidLoad
子类中实现了以下UIViewController
方法:
var scrollView = UIScrollView.newAutoLayoutView()
var contentView = UIView.newAutoLayoutView()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(scrollView)
scrollView.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsetsZero)
scrollView.addSubview(contentView)
contentView.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsetsZero)
contentView.autoMatchDimension(.Height, toDimension: .Height, ofView: view)
contentView.autoMatchDimension(.Width, toDimension: .Width, ofView: view)
contentView.addSubview(customView)
customView.autoPinEdgeToSuperviewEdge(.Top, withInset:0)
customView.autoPinEdgeToSuperviewEdge(.Left, withInset:15)
}
但是当我运行应用程序时,内容不会滚动。我找到了很少的PureLayout文档和示例,并且没有关于滚动视图的明确说明。有人可以帮我吗?
答案 0 :(得分:5)
在Scrollview中使用autolayout时,必须确保contentView中的每个视图都固定在所有4个边上。
你的customView只固定到TOP和LEFT,尝试固定到所有方面并使用autoSetDimension(.Height,toSize:1300)到一个大尺寸并观察它的工作:)
这是一个正在运行的示例代码
let instance = this.viewContainerRef.createComponent(this.componentFactory, 0).instance;
instance.message = "some text!!";
答案 1 :(得分:0)
这可能会帮助某人
func updateUI(){
self.view.backgroundColor = .white
self.view.addSubview(scrollView)
scrollView.addSubview(contentView)
contentView.addSubview(offer_title)
contentView.addSubview(offer_image)
contentView.addSubview(body)
scrollView.autoPinEdgesToSuperviewEdges()
contentView.autoPinEdgesToSuperviewEdges()
contentView.autoMatch(.width, to: .width, of: view)
offer_image.contentMode = .scaleToFill
offer_image.autoPinEdge(toSuperviewEdge: .top, withInset: 0)
offer_image.autoPinEdge(toSuperviewEdge: .trailing, withInset: 0)
offer_image.autoPinEdge(toSuperviewEdge: .leading, withInset: 0)
offer_image.autoSetDimension(.height, toSize: 300)
offer_title.autoPinEdge(.top, to: .bottom, of: offer_image, withOffset: 8)
offer_title.autoPinEdge(toSuperviewEdge: .trailing, withInset: 8)
offer_title.autoPinEdge(toSuperviewEdge: .leading, withInset: 8)
offer_title.autoSetDimension(.height, toSize: 60)
body.numberOfLines = 0
body.font = UIFont(name: "HelveticaNeueLT-Regular", size: 20)
body.autoPinEdge(.top, to: .bottom, of: offer_title, withOffset: 8)
body.autoPinEdge(toSuperviewEdge: .trailing, withInset: 8)
body.autoPinEdge(toSuperviewEdge: .leading, withInset: 8)
body.autoPinEdge(toSuperviewEdge: .bottom, withInset: 8)
}
并在 viewdidLoad
中调用它