gpt4 book ai didi

iphone - 相同的自动布局约束在纵向和横向上表现不同

转载 作者:行者123 更新时间:2023-12-03 20:51:52 27 4
gpt4 key购买 nike

我正在深入研究 iOS 6.0 新功能自动布局,我创建了一个示例应用程序,它有一个 View Controller 和两个 UIView 作为 subview 。我提供了以下约束:

Constraint for second view

Constraint for first view

当我在横向模式下执行以下应用程序并将其旋转到纵向时,它工作正常,但是当我在纵向模式下执行它并旋转到横向时,它会抛出异常:

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)
(
"<NSAutoresizingMaskLayoutConstraint:0x748cae0 h=--- v=--- H:[UIWindow:0x716a060(768)]>",
"<NSLayoutConstraint:0x716d980 V:[UIView:0x716d540]-(736)-| (Names: '|':UIView:0x716d0c0 )>",
"<NSLayoutConstraint:0x716d8c0 V:|-(20)-[UIView:0x716d540] (Names: '|':UIView:0x716d0c0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7176020 h=-&- v=-&- UIView:0x716d0c0.width == UIWindow:0x716a060.width - 20>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x716d980 V:[UIView:0x716d540]-(736)-| (Names: '|':UIView:0x716d0c0 )>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2012-10-22 11:37:37.297 AutoLayoutSample[679:c07] 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)
(
"<NSAutoresizingMaskLayoutConstraint:0x748cae0 h=--- v=--- H:[UIWindow:0x716a060(768)]>",
"<NSLayoutConstraint:0x716d880 V:[UIView:0x716d230]-(730)-| (Names: '|':UIView:0x716d0c0 )>",
"<NSLayoutConstraint:0x716d840 V:|-(20)-[UIView:0x716d230] (Names: '|':UIView:0x716d0c0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7176020 h=-&- v=-&- UIView:0x716d0c0.width == UIWindow:0x716a060.width - 20>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x716d880 V:[UIView:0x716d230]-(730)-| (Names: '|':UIView:0x716d0c0 )>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

我的问题是为什么当我在纵向模式下执行并旋转到横向模式时它会抛出异常?为什么约束的行为不同?

最佳答案

系统会自动将默认的调整大小蒙版转换为约束,然后与您的约束发生冲突。为两个 subview 添加对 [view setTranslatesAutoresizingMaskIntoConstraints:NO] 的调用,NSAutoresizingMaskLayoutConstraints 将消失,并且出现异常。

关于iphone - 相同的自动布局约束在纵向和横向上表现不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13005906/

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