我正在尝试以编程方式将左右 NSLayoutConstraint
添加到 view
。这是我的代码:
[self.mainView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-2.5-[_otherView]-2.5-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(self.otherView)]];
运行应用程序时出现以下错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse constraint format:
_otherView is not a key in the views dictionary.
最佳答案
NSDictionaryOfVariableBindings
的参数应该是 _otherView
。
它必须是与您在约束视觉格式中引用它的方式完全匹配的字符串。
关于ios - 以编程方式添加约束给我错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30178542/