如何根据iPhone的尺寸在Splash中设置不同的约束?
问题描述:
我正在做一个项目,其中一个要求是,公司标志必须出现在距离iPhone屏幕大小顶部10%的距离(如果它是iPhone 5,568高度,则应该是57) 。我可以应用一个约束,但据我所知,这是一个固定值,而不是相对值。 我一直在检查Xcode的“特性差异”功能,但由于我需要的所有尺寸都是wC hR,因此在这种情况下不起作用。 另一种解决方案是根据iPhone的型号应用不同的飞溅,但我不确定这是可能的。如何根据iPhone的尺寸在Splash中设置不同的约束?
有关它的任何想法?谢谢!
答
你可以很容易阿希在代码中也是如此。
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
使用宽高比约束。你能澄清一下吗?他们应该将宽度设为屏幕宽度的10%,还是应将徽标左侧的空间设置为屏幕宽度的10%? – Paulw11
这是一个垂直空间约束,我认为我只能将修正值应用于此。有什么办法让它变得相对? – Sylphos
诀窍是在商标旁放置一个占位符透明的'UIView',并将该视图的高度限制在屏幕高度的1/10处,并将商标的顶边限制在占位符的底边。 – Paulw11