iOS如何使用自动布局解决设计中的问题
嗨,我正在开发应用程序,在这里我有一个自定义单元格设计的UITableView。当我转到这个视图控制器时,我可以看到在设计中有很多问题。所以我想把它们修好。我只是很快就开始讨论这个问题,这就是我所看到的iOS如何使用自动布局解决设计中的问题,ios,swift,xcode,autolayout,ios-autolayout,Ios,Swift,Xcode,Autolayout,Ios Autolayout,嗨,我正在开发应用程序,在这里我有一个自定义单元格设计的UITableView。当我转到这个视图控制器时,我可以看到在设计中有很多问题。所以我想把它们修好。我只是很快就开始讨论这个问题,这就是我所看到的 Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayo
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2020-02-21 11:35:00.835363+0500 HIRING App[490:51013] [LayoutConstraints] 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.
(
"<NSLayoutConstraint:0x2828bada0 UIButton:0x139cd30e0'Auto Add'.width == 100 (active)>",
"<NSLayoutConstraint:0x2828bbd40 H:|-(0)-[UIButton:0x139cd30e0'Auto Add'] (active, names: '|':UIStackView:0x139bc3d50 )>",
"<NSLayoutConstraint:0x2828bbd90 H:[UIButton:0x139cd30e0'Auto Add']-(4)-| (active, names: '|':UIStackView:0x139bc3d50 )>",
"<NSLayoutConstraint:0x282beb4d0 H:[UIStackView:0x139bc3d50]-(4)-| (active, names: '|':UIView:0x139bc8970 )>",
"<NSLayoutConstraint:0x282beb520 H:|-(4)-[UIStackView:0x139bc3d50] (active, names: '|':UIView:0x139bc8970 )>",
"<NSLayoutConstraint:0x2828a6620 UIView:0x139cd5ed0.width == 0.4*UIView:0x139bcf9f0.width (active)>",
"<NSLayoutConstraint:0x2828a6710 H:|-(0)-[UIView:0x139cd5ed0] (active, names: '|':UIView:0x139bcf9f0 )>",
"<NSLayoutConstraint:0x2828a6800 H:[UIView:0x139cd5ed0]-(1)-[UIView:0x139bc8970] (active)>",
"<NSLayoutConstraint:0x2828a75c0 H:[UIView:0x139bc8970]-(0)-| (active, names: '|':UIView:0x139bcf9f0 )>",
"<NSLayoutConstraint:0x2828aa3f0 UIView:0x139bcf9f0.width == 0.75*UIView:0x139cd2230.width (active)>",
"<NSLayoutConstraint:0x2828f2d50 H:|-(0)-[UIView:0x139cd2ab0] (active, names: '|':UIView:0x139cd7ec0 )>",
"<NSLayoutConstraint:0x2828fbd40 UIView:0x139cd2ab0.width == 0.32*UIView:0x139cd7ec0.width (active)>",
"<NSLayoutConstraint:0x282812ee0 H:[UIView:0x139cd2ab0]-(0)-[UIView:0x139cd2230] (active)>",
"<NSLayoutConstraint:0x282813890 H:[UIView:0x139cd2230]-(0)-| (active, names: '|':UIView:0x139cd7ec0 )>",
"<NSLayoutConstraint:0x282beb660 H:|-(0)-[UIView:0x139cd7ec0] (active, names: '|':UIView:0x139ccca70 )>",
"<NSLayoutConstraint:0x282beb750 UIView:0x139cd7ec0.trailing == UIButton:0x139cd4240.trailing (active)>",
"<NSLayoutConstraint:0x282beb7f0 H:[UIButton:0x139cd4240]-(4)-| (active, names: '|':UIView:0x139ccca70 )>",
"<NSLayoutConstraint:0x282beba20 H:|-(8)-[UIView:0x139ccca70] (active, names: '|':UITableViewCellContentView:0x139cf34c0 )>",
"<NSLayoutConstraint:0x282beba70 H:[UIView:0x139ccca70]-(8)-| (active, names: '|':UITableViewCellContentView:0x139cf34c0 )>",
"<NSLayoutConstraint:0x2828b9d60 'fittingSizeHTarget' UITableViewCellContentView:0x139cf34c0.width == 414 (active)>"
)
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
2020-02-21 11:35:00.835363+0500招聘应用程序[490:51013][LayoutConstraints]无法同时满足约束条件。
可能下面列表中至少有一个约束是您不想要的。
试试这个:
(1) 看看每一个约束,试着找出你不期望的;
(2) 找到添加了不需要的约束的代码,然后修复它。
(
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""
)
这是我第一次修复UI视图。我在这方面得到了很大的帮助。但我真的不明白他是如何解决这个问题的。我做了同样的事情来打印我的设计问题的细节,所以我得到了一些非常清楚的东西,但我仍然不知道该先解决哪件事。请引导我完成或分享一些可以帮助我识别问题的内容。提前谢谢。下面是我在SO链接中建议应用符号断点时得到的跟踪
UIWindow:0x137e36480
| UILayoutContainerView:0x137d41200
| | UITransitionView:0x137d41710
| | | UIViewControllerWrapperView:0x139baa680
| | | | UILayoutContainerView:0x137e36280
| | | | | UINavigationTransitionView:0x137e58cd0
| | | | | | UIViewControllerWrapperView:0x137d64520
| | | | | | | •UIView:0x137ee7d50
| | | | | | | | *<UILayoutGuide: 0x2832fad80 - "UIViewSafeAreaLayoutGuide", layoutFrame = {{0, 20}, {414, 667}}, owningView = <UIView: 0x137ee7d50; frame = (0 0; 414 736); autoresize = W+H; layer = <CALayer: 0x280b09ac0>>>
| | | | | | | | *UIView:0x137ee7f30
| | | | | | | | *UIView:0x137ee8110
| | | | | | | | | *UISegmentedControl:0x137ee59c0 alignmentRect = (65 16; 284 28) for frame = (65 16; 284 29);
| | | | | | | | | | UISegment:0x137ee5c30
| | | | | | | | | | | UISegmentLabel:0x137ee5ed0'AUTO ADD HISTORY'
| | | | | | | | | | | UIImageView:0x137ee6510
| | | | | | | | | | UISegment:0x137dbb4d0
| | | | | | | | | | | UISegmentLabel:0x137dbba00'AUTO ADD ON'
| | | | | | | | | | | UIImageView:0x137dbc320
| | | | | | | | | | UISegment:0x137ee6740
| | | | | | | | | | | UISegmentLabel:0x137ee69e0'ALL'
| | | | | | | | | | | UIImageView:0x137ee6cd0
| | | | | | | | | *UILabel:0x137ee7070'Swipe "Right" to send ite...'
| | | | | | | | | *UIView:0x137ee82f0
| | | | | | | | | | *UIView:0x137ee84d0
| | | | | | | | | | | *UIView:0x137ee86b0
| | | | | | | | | | | | *UIButton:0x137ee5060'Item/Purchase Dt'
| | | | | | | | | | | | | UIButtonLabel:0x137dc4110'Item/Purchase Dt'
| | | | | | | | | | | *UIView:0x137ee8890
| | | | | | | | | | | | *UIView:0x137ee8a70
| | | | | | | | | | | | | *UIButton:0x137ee56a0'QTY'
| | | | | | | | | | | | | | UIButtonLabel:0x137dc3e10'QTY'
| | | | | | | | | | | | *UIView:0x137dbcfd0
| | | | | | | | | | | | | *UIView:0x137dbd1b0
| | | | | | | | | | | | | | *UIButton:0x137ee5380'Expiry'
| | | | | | | | | | | | | | | UIButtonLabel:0x137dc3b10'Expiry'
| | | | | | | | | | | | | *UIView:0x137dbd390
| | | | | | | | | | | | | | *UIButton:0x137ee4940'Buy Again'
| | | | | | | | | | | | | | | UIButtonLabel:0x137dc2c00'Buy Again'
| | | | | | | | | *UITableView:0x1389a6800
| | | | | | | | | | HIRING_App.ItemPantryListCell:0x1389dda00
| | | | | | | | | | | •UITableViewCellContentView:0x139bc09b0, MISSING HOST CONSTRAINTS
| | | | | | | | | | | | *UIView:0x139bc0ba0
| | | | | | | | | | | | | *UIView:0x139bc0d80
| | | | | | | | | | | | | | *UIView:0x139bc0f60
| | | | | | | | | | | | | | | *UILabel:0x139bc1140'transaxle'
| | | | | | | | | | | | | | | *UILabel:0x139bc1430'02/21/2020'
| | | | | | | | | | | | | | *UIView:0x139bc1720
| | | | | | | | | | | | | | | *UIView:0x139bc1900
| | | | | | | | | | | | | | | | *UILabel:0x139bc1ae0'1 Item'
| | | | | | | | | | | | | | | *UIView:0x139bc1dd0
| | | | | | | | | | | | | | | | *UIView:0x139bc1fb0
| | | | | | | | | | | | | | | | | *UIStackView:0x139bc2190
| | | | | | | | | | | | | | | | | | *<_UILayoutSpacer: 0x2834f5860 - "UISV-alignment-spanner", layoutFrame = {{0, 0}, {75.333333333333329, 0}}, owningView = <UIStackView: 0x139bc2190; frame = (0 37.5; 75.5 32.5); opaque = NO; autoresize = RM+BM; layer = <CATransformLayer: 0x280a94dc0>>>- AMBIGUOUS LAYOUT for _UILayoutSpacer:0x2834f5860'UISV-alignment-spanner'.minY{id: 7931}, _UILayoutSpacer:0x2834f5860'UISV-alignment-spanner'.Height{id: 7932}
| | | | | | | | | | | | | | | | | | *UILabel:0x139bc2390'Label'- AMBIGUOUS LAYOUT for UILabel:0x139bc2390'Label'.minY{id: 7863}
| | | | | | | | | | | | | | | | | | *UIButton:0x139bc2680' Expiry Alert'
| | | | | | | | | | | | | | | | *UIView:0x139cc16c0
| | | | | | | | | | | | | | | | | *UIStackView:0x139cc2150
| | | | | | | | | | | | | | | | | | *<_UILayoutSpacer: 0x2834f11d0 - "UISV-alignment-spanner", layoutFrame = {{0, 0}, {104, 0}}, owningView = <UIStackView: 0x139cc2150; frame = (4 18.5; 104 70); opaque = NO; autoresize = RM+BM; layer = <CATransformLayer: 0x280a91460>>>- AMBIGUOUS LAYOUT for _UILayoutSpacer:0x2834f11d0'UISV-alignment-spanner'.minY{id: 7960}, _UILayoutSpacer:0x2834f11d0'UISV-alignment-spanner'.Height{id: 7961}
| | | | | | | | | | | | | | | | | | *UILabel:0x139cc2350- AMBIGUOUS LAYOUT for UILabel:0x139cc2350.minY{id: 7906}
| | | | | | | | | | | | | | | | | | *UIButton:0x139bc2c40'Auto Add'
| | | | | | | | | | | | | | | | | | | UIImageView:0x139bc37c0
| | | | | | | | | | | | | *UIButton:0x139cc3d80
| | | | | | | | | | | | | | UIImageView:0x139bc67f0
| | | | | | | | | | | | | *UIButton:0x139cc40a0
| | | | | | | | | | | | | | UIImageView:0x139bc6a20
| | | | | | | | | | | _UITableViewCellSeparatorView:0x139bc29a0
| | | | | | | | | | UIImageView:0x137ef5b00
| | | | | | | | | | UIImageView:0x137ef5d30
| | UITabBar:0x137d3eb00
| | | _UIBarBackground:0x137d402a0
| | | | UIImageView:0x137d40730
| | | | UIVisualEffectView:0x137d40960
| | | | | _UIVisualEffectBackdropView:0x137e17780
| | | | | _UIVisualEffectSubview:0x137e412b0
| | | UITabBarButton:0x137e4f830
| | | | UITabBarSwappableImageView:0x137d281a0
| | | | UITabBarButtonLabel:0x137e4fb50'MY LISTS'
| | | | _UIBadgeView:0x137d5e7f0
| | | | | UIImageView:0x137d60290
| | | | | UILabel:0x137d5f4b0'1'
| | | UITabBarButton:0x137d3f0d0
| | | | UITabBarSwappableImageView:0x137d3f900
| | | | UITabBarButtonLabel:0x137d3f5e0'CART'
| | | | _UIBadgeView:0x137d60ac0
| | | | | UIImageView:0x137d60cd0
| | | UITabBarButton:0x137e50380
| | | | UITabBarSwappableImageView:0x137e50bb0
| | | | UITabBarButtonLabel:0x137e50890'PANTRY'
| | | | _UIBadgeView:0x137d60f00
| | | | | UIImageView:0x137d61110
| | | | | UILabel:0x139cae990'1'
| | | UITabBarButton:0x137e50e00
| | | | UITabBarSwappableImageView:0x137e51630
| | | | UITabBarButtonLabel:0x137e51310'TODO'
| | | | _UIBadgeView:0x137d61340
| | | | | UIImageView:0x137d61550
| | | UITabBarButton:0x137e51880
| | | | UITabBarSwappableImageView:0x137e520b0
| | | | UITabBarButtonLabel:0x137e51d90'MORE'
Legend:
* - is laid out with auto layout
+ - is laid out manually, but is represented in the layout engine because translatesAutoresizingMaskIntoConstraints = YES
• - layout engine host
ui窗口:0x137e36480
|UILayoutContainerView:0x137d41200
|| UITransitionView:0x137d41710
|| | UIViewControllerRapperView:0x139baa680
|| | | UILayoutContainerView:0x137e36280
|| | | | UINavigationTransitionView:0x137e58cd0
|| | | | | UIViewControllerRapperView:0x137d64520
|| | | | | | | UIView:0x137ee7d50
| | | | | | | | *
|| | | | | | |*UIView:0x137ee7f30
|| | | | | | |*UIView:0x137ee8110
|| | | | | | | | | | | | | | | | | | |*UISegmentedControl:0x137ee59c0 alignmentRect=(65 16;284 28)用于帧=(65 16;284 29;
|| | | | | | | | |取消分段:0x137ee5c30
|| | | | | | | | | | | | UISegmentLabel:0x137ee5ed0“自动添加历史记录”
|| | | | | | | | | UIImageView:0x137ee6510
|| | | | | | | | | UISegment:0x137dbb4d0
|| | | | | | | | | | | | | UISegmentLabel:0x137dbba00'自动加载项'
|| | | | | | | | | UIImageView:0x137dbc320
|| | | | | | | | | |取消分段:0x137ee6740
|| | | | | | | | | | | | | | UISegmentLabel:0x137ee69e0'ALL'
|| | | | | | | | | UIImageView:0x137ee6cd0
|| | | | | | | | | | | |*UILabel:0x137ee7070“向右滑动”以发送到
|| | | | | | | | | UIView:0x137ee82f0
|| | | | | | | | | |*UIView:0x137ee84d0
|| | | | | | | | | | |*UIView:0x137ee86b0
|| | | | | | | | | | | | | | | | | | | | | | | | |*UI
|| | | | | | | | | | | | | | | | | | | | UIButtonLabel:0x137dc4110'项目/采购Dt'
|| | | | | | | | | | | |*UIView:0x137ee8890
|| | | | | | | | | | | | UIView:0x137ee8a70
|| | | | | | | | | | | | | | | | UIButton:0x137ee56a0‘数量’
|| | | | | | | | | | | | | | | UIButtonLabel:0x137dc3e10'数量'
|| | | | | | | | | | | |*UIView:0x137dbcfd0
|| | | | | | | | | | | | | UIView:0x137dbd1b0
|| | | | | | | | | | | | | | | | | | | | | | | |*UIButton:
|| | | | | | | | | | | | | | | | | | | UIButtonLabel:0x137dc3b10'到期'
|| | | | | | | | | | | | | UIView:0x137dbd390
|| | | | | | | | | | | | | | | | | UIButton:0x137ee4940“再次购买”
|| | | | | | | | | | | | | | | | | | | | UIButtonLabel:0x137dc2c00‘再次购买’
|| | | | | | | |*UITableView:0x1389a6800
|| | | | | | | | | | | | | | | | | | | |招聘|应用程序项Pantrylistcell
|| | | | | | | | | | | | | UITableViewCellContentView:0x139bc09b0,缺少主机约束
|| | | | | | | | | | | |*UIView:0x139bc0ba0
|| | | | | | | | | | | | |*UIView:0x139bc0d80
|| | | | | | | | | | | | | | UIView:0x139bc0f60
|| | | | | | | | | | | | | | | | | | | | | | | | |*UILabel:
|| | | | | | | | | | | | | | | UILabel:0x139bc1430'02/21/2020'
|| | | | | | | | | | | | | UIView:0x139bc1720
|| | | | | | | | | | | | | | UIView:0x139bc1900
|| | | | | | | | | | | | | | | | UILabel:0x139bc1ae0'1项目'
|| | | | | | | | | | | | | | UIView:0x139bc1dd0
|| | | | | | | | | | | | | | | | | | UIView:0x139bc1fb0
|| | | | | | | | | | | | | | | | |*UIStackView:0x139bc2190
|| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|| | | | | | | | | | | | | | | | | | | | | | | | | UILabel:
|| | | | | | | | | | | | | | | | | | | | | | | | | | | | |*
|| | | | | | | | | | | | | | | | UIView:0x139cc16c0
| | | | | | | | | |