Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Can';无法摆脱自动约束警告_Ios_Objective C_Uitableview_Autolayout_Constraints - Fatal编程技术网

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。

    否则,您必须显示视图控制器的屏幕截图以及约束 谢谢

您能提供更多的上下文吗?您现在对tableview有哪些约束?你想做什么动画?你想做什么样的动画?什么对象将设置动画?若要避免所有警告,请确定可能具有受动画影响的自动布局的视图,然后将其删除。你可以使用自动布局和动画,如果你喜欢。我会编辑原始文章,包括更多的信息,我很抱歉没有提供它放在首位。
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];
    }];
}