gpt4 book ai didi

iOS 8 工作正常,iOS 7 由于 View 转换影响布局约束而无法同时满足约束

转载 作者:可可西里 更新时间:2023-11-01 06:17:35 33 4
gpt4 key购买 nike

我正在做一个项目,我们已经在 iOS 8 设备上测试了几周。今天我决定在 iOS 7.1 模拟器上测试它,我的应用程序记录了臭名昭著的约束错误:

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)

我知道自动布局,并且几乎不可能在此处演示示例(我需要将几乎整个项目放在这里,因为有许多执行自定义绘图的 View ,许多与其他 View 相关的约束等)。在 iOS 8 上,一切都完美绘制。在 iOS 7 上,我的一些 View 只有零宽度/高度(已调试),而另一些 View 的宽度/高度与这些 View 相关 绘制完美。我知道的一件事是,我仔细检查过没有涉及容器边距的限制。我知道它是 iOS 8 中的新功能。为什么可能是另一个原因?如果有帮助,这里是完整的跟踪:

(
"<NSLayoutConstraint:0x7a0e86b0 H:|-(0)-[UIView:0x7a17dfe0] (Names: '|':UIView:0x7a0e7a40 )>",
"<NSLayoutConstraint:0x7a0e86e0 H:[UIView:0x7a17dfe0]-(0)-| (Names: '|':UIView:0x7a0e7a40 )>",
"<NSAutoresizingMaskLayoutConstraint:0x79ecc850 h=--& v=--& H:[UIView:0x7a0e7a40(320)]>",
"<NSAutoresizingMaskLayoutConstraint:0x7a00add0 h=-&- v=-&- UITransitionView:0x79f9c110.width == UILayoutContainerView:0x79f9c070.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7a00a550 h=-&- v=-&- UILayoutContainerView:0x79f9c070.width == UIViewControllerWrapperView:0x7a1b0340.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7a009840 h=-&- v=-&- UIViewControllerWrapperView:0x7a1b0340.width == UINavigationTransitionView:0x7a18cfd0.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7a008cc0 h=-&- v=-&- UINavigationTransitionView:0x7a18cfd0.width == UILayoutContainerView:0x7a0f17b0.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7a008160 h=-&- v=-&- UILayoutContainerView:0x7a0f17b0.width == UIView:0x7a17dfe0.width>",
"<NSLayoutConstraint:0x7cdcc000 MyAppMoodTypeSelectionView:0x7f19ddf0.width == 2.5*MyAppFaceView:0x7f19e8b0.width>",
"<NSLayoutConstraint:0x7cde0380 MyAppMoodTypeSelectionView:0x7f19ddf0.width == 0.75*UIView:0x7cddfcf0.width>",
"<NSLayoutConstraint:0x7cde0470 MyAppRoundView:0x7a005e00.width == MyAppFaceView:0x7f19e8b0.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7f1a0a20 h=-&- v=-&- UIView:0x7cddfcf0.width == UIViewControllerWrapperView:0x7cde15c0.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7f1a10d0 h=-&- v=-&- UIViewControllerWrapperView:0x7cde15c0.width == UINavigationTransitionView:0x7cdd93a0.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7f1a1750 h=-&- v=-&- UINavigationTransitionView:0x7cdd93a0.width == UILayoutContainerView:0x7a053c60.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7f1a1e90 h=-&- v=-&- UILayoutContainerView:0x7a053c60.width == UIViewControllerWrapperView:0x7cdddc10.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7f1a25e0 h=-&- v=-&- UIViewControllerWrapperView:0x7cdddc10.width == UITransitionView:0x79f9c110.width>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7cdcc000 MyAppMoodTypeSelectionView:0x7f19ddf0.width == 2.5*MyAppFaceView:0x7f19e8b0.width>

在 iOS 8.1 上,无论是在设备上还是在模拟器上,完全相同的应用程序在所有约束正确且满足的情况下工作得非常好。在 iOS 7.1 上,即使在相同的屏幕尺寸上,我也会收到这些错误。

我已经尝试在所有 View 上关闭 translatesAutoresizingMaskIntoConstraints(主容器 View 除外,否则屏幕会变黑)。

会是什么原因呢?除了新的容器边距限制之外,在自动布局方面,从 iOS 7 到 iOS 8 到底发生了什么变化?

更新:我的类(class)中有转换更改代码。显然,在 iOS 8 上,布局约束不受变换影响,但在 iOS 7 上,它们受变换影响。不过,仍在寻找没有硬编码值的解决方案。

最佳答案

cell.contentView.frame = cell.bounds

关于iOS 8 工作正常,iOS 7 由于 View 转换影响布局约束而无法同时满足约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27174794/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com