看起来像是一个不用脑子但我无法让这个简单的设置正确! 请注意,我不想通过代码添加约束,而是通过IB执行所有操作:
我做了什么:
我期待的是什么: 在应用程序启动和视图加载时,视图控制器的主视图及其子视图(集合视图)应为320x480或320x568,具体取决于设备屏幕大小。
实际发生的事情: 在应用程序启动和视图加载时,视图控制器的主视图调整为320x480,但集合视图停留在320x568,这是我在IB中给出的设计时尺寸。
我也遇到了约束冲突:
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:0xed66060 V:[UICollectionView:0x13a79400]-(-548)-[_UILayoutGuide:0xed65c90]>",
"<NSLayoutConstraint:0xed66090 V:[UICollectionView:0x13a79400]-(0)-[_UILayoutGuide:0xed65da0]>",
"<_UILayoutSupportConstraint:0xed4d4e0 V:|-(0)-[_UILayoutGuide:0xed65c90] (Names: '|':UIView:0xed65c00 )>",
"<_UILayoutSupportConstraint:0xed65730 V:[_UILayoutGuide:0xed65da0(0)]>",
"<_UILayoutSupportConstraint:0xed651f0 _UILayoutGuide:0xed65da0.bottom == UIView:0xed65c00.bottom>",
"<NSAutoresizingMaskLayoutConstraint:0xed72ee0 h=--& v=--& V:[UIView:0xed65c00(480)]>"
)
答案 0 :(得分:0)
translatesAutoresizingMaskIntoConstraints = YES可能适用于您的顶级(主)视图,这会自动创建其他约束,这与“接口”构建器中创建的约束冲突。为您的主视图设置translatesAutoresizingMaskIntoConstraints = NO并让我们知道它是如何进行的。