1

サブクラスに次の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 のドキュメントと例はほとんど見つかりません。また、スクロール ビューについても明確なものはありません。誰かがこれで私を助けてくれますか?

4

2 に答える 2

6

Scrollview で autolayout を使用する場合、contentView 内のすべてのビューが 4 つの側面すべてに固定されていることを確認する必要があります。

customView は TOP と LEFT にのみ固定されています。すべての側面に固定し、autoSetDimension(.Height, toSize: 1300) を大きなサイズに使用して、動作を確認してください:)

ここに動作しているサンプルコードがあります

    // background
    view.backgroundColor = UIColor.lightGrayColor()

    // ScrollView setup
    let scrollView = UIScrollView()
    scrollView.backgroundColor = UIColor.blueColor()
    view.addSubview(scrollView)
    scrollView.autoPinEdgesToSuperviewEdges()

    let scrollContentView = UIView()
    scrollContentView.backgroundColor = UIColor.redColor()
    scrollView.addSubview(scrollContentView)
    scrollContentView.autoPinEdgesToSuperviewEdges()
    scrollContentView.autoMatchDimension(.Width, toDimension: .Width, ofView: view)

    let dummy = UIView()
    dummy.backgroundColor = UIColor.whiteColor()
    scrollContentView.addSubview(dummy)
    dummy.autoSetDimension(.Height, toSize: 1300)
    dummy.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsetsMake(20, 20, 20, 20))
于 2016-08-19T23:10:39.583 に答える