2016-03-20 74 views
0

我有一個UIViewController子下面viewDidLoad方法實現:無法設置滾動視圖與PureLayout

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文檔和示例,並沒有關於滾動視圖的清楚。有人能幫助我嗎?

回答

2

當您使用滾動視圖自動佈局時,您必須確保contentView中的每個視圖都固定在所有4邊。

您customView只固定到頂部和左側,試圖牽制各方意見,並使用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))