为什么自动布局预览和实际设备不匹配

4

我正在进行Xamarin.iOS开发,我在Xcode中使用autolayout来设计UI界面。

在Xcode的预览模式下,我的UI表现良好,但是在一些设备上,比如iPhone 5s和iPhone 6s Plus上,界面显示与预览不同。

有人能解释一下为什么会出现这种情况,并告诉我怎样解决吗?

谢谢!


3
请提供有关您遇到的问题的更多信息。具体而言,结果看起来是什么样子?UI是否完全混乱或者只是不能在更大的屏幕上进行拉伸? - 0xNSHuman
1
我有一个母视图,它距离顶部和底部视图各20像素。我使用顶部和底部垂直间距来布局引导线来实现这一点,但在 iPhone 5s 中,底部视图的垂直间距似乎相隔100像素。 - Sharath
1个回答

0

有很多原因会导致自动布局错误。其中一些是由于不同的屏幕比例,另一些是由于不同的iOS版本。

您应该查看调试器输出并检查是否有类似以下消息:

Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSLayoutConstraint:0x7fc82d3e18a0 H:[UIView:0x7fc82aba1210(768)]>",
    "<NSLayoutConstraint:0x7fc82d6369e0 H:[UIView:0x7fc82aba1210]-(0)-|   (Names: '|':UIView:0x7fc82d6b9f80 )>",
    "<NSLayoutConstraint:0x7fc82d636a30 H:|-(0)-[UIView:0x7fc82aba1210]   (Names: '|':UIView:0x7fc82d6b9f80 )>",
    "<NSLayoutConstraint:0x7fc82d3e7fd0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fc82d6b9f80(50)]>"
)

只需要调试它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接