2017-09-01 71 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