Ios Can';无法摆脱自动约束警告
我最近在制作Ios Can';无法摆脱自动约束警告,ios,objective-c,uitableview,autolayout,constraints,Ios,Objective C,Uitableview,Autolayout,Constraints,我最近在制作UITableView的动画时遇到了一个问题。原来问题是由自动布局约束引起的。我使用以下代码禁用了UITableView的自动布局: myTableView.translatesAutoresizingMaskIntoConstraints = YES; 这解决了问题,但现在每次我设置UITableView动画时,我都会打破帧上的约束,并得到以下警告 Unable to simultaneously satisfy constraints. Probably at leas
UITableView
的动画时遇到了一个问题。原来问题是由自动布局约束引起的。我使用以下代码禁用了UITableView
的自动布局:
myTableView.translatesAutoresizingMaskIntoConstraints = YES;
这解决了问题,但现在每次我设置UITableView
动画时,我都会打破帧上的约束,并得到以下警告
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)
(
"<NSIBPrototypingLayoutConstraint:0x170a95db0 'IB auto generated at build time for view with fixed frame' V:|-(538)-[UITableView:0x140330c00] (Names: '|':UIView:0x170199640 )>",
"<NSIBPrototypingLayoutConstraint:0x170c9d010 'IB auto generated at build time for view with fixed frame' V:[UITableView:0x140330c00(220)]>",
"<NSAutoresizingMaskLayoutConstraint:0x175e850a0 h=--& v=--& UITableView:0x140330c00.midY == + 458>",
"<NSAutoresizingMaskLayoutConstraint:0x175c97b10 h=-&- v=-&- 'UIView-Encapsulated-Layout-Top' V:|-(0)-[UIView:0x170199640] (Names: '|':UITransitionView:0x143942020 )>"
)
Will attempt to recover by breaking constraint
<NSIBPrototypingLayoutConstraint:0x170a95db0 'IB auto generated at build time for view with fixed frame' V:|-(538)-[UITableView:0x140330c00] (Names: '|':UIView:0x170199640 )>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
从上面可以看出,我所做的就是改变帧的y分量。最初,
UITableView
的框架具有583的y分量,这在原始约束警告
中提到。我没有为UITableView
设置任何附加约束,只需将其从对象库中拖动并移动到其初始最小化位置。我猜通过改变帧y分量,我打破了默认设置的固定约束。我希望这些补充信息能有所帮助。如何解决此问题?您的tableview出现问题您已经为tableview的高度设置了多个值
约束-538高度
tableview
因为您已经为tableview设置了固定高度
- 如果您是根据导航栏设置tableview,则表示在 导航栏,它应该是504而不是
- 如果只有一个TableView,则可以删除一个
将其固定到0,0,0,0。
否则,您必须显示视图控制器的屏幕截图以及约束 谢谢
UIImage *downImage = [UIImage imageNamed:@"arrowDown.png"];
UIImage *upImage = [UIImage imageNamed:@"arrowUp.png"];
UIButton *btnExpandCompress = (UIButton *)sender;
[btnExpandCompress setEnabled:NO];
if (showingTable)
{
[UIView animateWithDuration:0.7 animations:^{
CGRect frame = animatedTable.frame;
frame.origin.y += animatedTable.frame.size.height - 30;
animatedTable.frame = frame;
} completion:^(BOOL finished) {
showingTable = NO;
[btnExpandCompress setEnabled:YES];
[btnExpandCompress setBackgroundImage:upImage forState:UIControlStateNormal];
}];
}
else
{
[UIView animateWithDuration:0.7 animations:^{
CGRect frame = animatedTable.frame;
frame.origin.y -= animatedTable.frame.size.height - 30;
animatedTable.frame = frame;
} completion:^(BOOL finished) {
showingTable = YES;
[btnExpandCompress setEnabled:YES];
[btnExpandCompress setBackgroundImage:downImage forState:UIControlStateNormal];
}];
}