简体   繁体   English

iOS 8运行正常,由于视图转换影响布局约束,iOS 7无法同时满足约束

[英]iOS 8 works fine, iOS 7 gets Unable to simultaneously satisfy constraints due to view transform affecting layout constraints

I'm working on a project which we've been testing on iOS 8 devices for a few weeks. 我正在研究一个项目,我们已经在iOS 8设备上测试了几个星期。 Today I've decided to test it on iOS 7.1 Simulator and my app logged the infamous constraints error: 今天,我决定在iOS 7.1 Simulator上对其进行测试,并且我的应用记录了臭名昭著的约束错误:

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) 

I know about auto layout, and it's near impossible to demonstrate a sample (I'd need to put almost the whole project here as there are many views that do custom drawing, many constraints related to other views etc) here. 我知道自动布局,几乎不可能展示一个示例(我需要将几乎整个项目放在这里,因为这里有很多视图可以进行自定义绘制,许多约束与其他视图相关,等等)。 On iOS 8 everything draws perfectly. 在iOS 8上,一切都完美绘制。 On iOS 7, some of my views just have zero width/height (debugged them) while some others with related width/height to those views draw perfectly. 在iOS 7上,我的某些视图的宽度/高度仅为零(已对其进行调试),而另一些视图的宽度/高度与这些视图相关的则完美绘制。 One thing I know is that I've double checked that there are no constraints involving container margins . 我知道的一件事是,我仔细检查了没有涉及容器边距的约束 I know it's new in iOS 8. Why could be another reason? 我知道它是iOS 8中的新功能。为什么会是另一个原因? Here is the full trace if it helps: 如果有帮助,这是完整的跟踪信息:

(
    "<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>

The very same app works perfectly fine with all the constraints correct and satisfied on iOS 8.1, both on device and simulator. 相同的应用程序可以完美运行,并且在iOS 8.1上正确且满足所有约束条件,无论是在设备上还是在模拟器上。 On iOS 7.1, I'm getting these error even on same screen sizes. 在iOS 7.1上,即使在相同的屏幕尺寸下 ,我也会遇到这些错误

I've tried turning translatesAutoresizingMaskIntoConstraints off on all views (expect the main container view, otherwise the screen goes black). 我试过关闭所有视图上的translatesAutoresizingMaskIntoConstraints (期望主容器视图,否则屏幕变黑)。

What would be the reason? 请问是什么原因? What exactly did change from iOS 7 to iOS 8 in regards to auto layout other than the new container margin constraints? 从iOS 7到iOS 8,除了新的容器边距约束之外,在自动布局方面究竟发生了什么变化?

UPDATE: I have transform-changing code in my class. 更新:我的课堂上有变换变换代码。 Apparently, on iOS 8, the layout constraints are not affected by the transform but on iOS 7, they are affected by the transform. 显然,在iOS 8,布局的限制不会受到变换,但在iOS 7,它们变换的影响。 Still looking for a solution though, without hard-coding values. 仍在寻找解决方案,而没有对值进行硬编码。

cell.contentView.frame = cell.bounds

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM