2017-09-01 72 views
0

我使用PureLayout進行編程視圖約束。我以爲我讓他們正確設置,大小,X和Y解決。但是,當我在SE上運行我的代碼和7 Plus時,視圖沒有正確對齊。正確設置PureLayout約束?

下面是代碼片段:

if (shouldSetupConstraints) { 
     // bg 
     backgroundView.autoPinEdgesToSuperviewEdges() 
     // positions 
     emailTextField.autoPinEdge(toSuperviewEdge: .top, withInset: 170) 
     emailTextField.autoPinEdge(toSuperviewEdge: .left, withInset: 60) 
     passwordTextField.autoPinEdge(toSuperviewEdge: .top, withInset: 250) 
     passwordTextField.autoPinEdge(toSuperviewEdge: .left, withInset: 60) 
     loginButton.autoPinEdge(toSuperviewEdge: .top, withInset: 350) 
     loginButton.autoPinEdge(toSuperviewEdge: .left, withInset: 75) 
     recoverButton.autoPinEdge(toSuperviewEdge: .top, withInset: 410) 
     recoverButton.autoPinEdge(toSuperviewEdge: .left, withInset: 60) 
     // confirms setup is done 
     shouldSetupConstraints = false 
    } 

我認爲屏幕分獲視網膜上的屏幕一樣,那麼爲什麼會有差異與這些數字嗎?

回答

0

對於iPhone SE(320x568)和7 Plus(414x736),邏輯分辨率爲不一樣

而不是從頂部或左側定位每個約束,請嘗試使用給定超視圖的每一側。

+0

所以使用所有4個方向,但相同的值應該翻譯,而不是從1定位? – jackdm

+0

不要像現在這樣使用相同的值,根據佈局計算正確的值。 – the4kman

+0

即時通訊不知道我得到你的意思,像一個如果其他取決於正在使用的設備? – jackdm