如何根据iPhone的尺寸在Splash中设置不同的约束?

问题描述:

我正在做一个项目,其中一个要求是,公司标志必须出现在距离iPhone屏幕大小顶部10%的距离(如果它是iPhone 5,568高度,则应该是57) 。我可以应用一个约束,但据我所知,这是一个固定值,而不是相对值。 我一直在检查Xcode的“特性差异”功能,但由于我需要的所有尺寸都是wC hR,因此在这种情况下不起作用。 另一种解决方案是根据iPhone的型号应用不同的飞溅,但我不确定这是可能的。如何根据iPhone的尺寸在Splash中设置不同的约束?

有关它的任何想法?谢谢!

+0

使用宽高比约束。你能澄清一下吗?他们应该将宽度设为屏幕宽度的10%,还是应将徽标左侧的空间设置为屏幕宽度的10%? – Paulw11

+0

这是一个垂直空间约束,我认为我只能将修正值应用于此。有什么办法让它变得相对? – Sylphos

+0

诀窍是在商标旁放置一个占位符透明的'UIView',并将该视图的高度限制在屏幕高度的1/10处,并将商标的顶边限制在占位符的底边。 – Paulw11

您可以使用占位符视图来创建所需的垂直空间。

添加UIView上面的标志:

enter image description here

约束本视图到根视图 的顶部的顶部约束本视图的底部到标志 约束高度顶部此视图可根视图的高度的1/10的

enter image description here

+0

我想知道如何做到这一点哈哈哈感谢它的工作!!!!! – Sylphos

你可以很容易阿希在代码中也是如此。

logoImageView.translatesAutoresizingMaskIntoConstraints = false 

// This will keep your imageView 10% from the top 
NSLayoutConstraint(item: logoImageView, attribute: .top, relatedBy: .equal, toItem: self.view, attribute: .topMargin, multiplier: 1.0, constant: self.view.frame.size.height/10).isActive = true 

// Additional You will want your imageView to be centered. 
NSLayoutConstraint(item: logoImageView, attribute: .centerX, relatedBy: .equal, toItem: self.view, attribute: .centerX, multiplier: 1.0, constant: 0).isActive = true 
+0

因为它在飞溅,我无法编码。这是主要问题 – Sylphos