我收到以下错误:
Could not resolve symbolic constant for constraint, because: Could not find relevant edges for attributes: centerX and centerX.
Use a symbolic breakpoint at NSLayoutConstraintFailedToFindDefaultResolvedValueForSymbolicConstant to debug.
如果我在 NSLayoutConstraintFailedToFindDefaultResolvedValueForSymbolicConstant
处添加断点,它会在这一行停止:
[self.customNavigationBar.widthAnchor constraintEqualToAnchor:self.view.widthAnchor].active = YES;
此行在 View Controller 的 viewDidLoad
中调用。 customNavigationBar
是从 nib 加载的 UIView,它已作为 subview 添加到 self.view
。
如果我尝试打印出我正在使用的 anchor ,一切似乎都正常:
(lldb) po self.customNavigationBar.widthAnchor
<NSLayoutDimension:0x17446cc80 "UIView:0x10115c160.width">
(lldb) po self.view.widthAnchor
<NSLayoutDimension:0x170667080 "UIView:0x1012ae550.width">
最佳答案
此错误来自您为 NSLayoutConstraint
选择的构造函数。
你可能有这样的事情:
view.topAnchor.constraint(equalToSystemSpacingBelow: otherView.centerYAnchor, multiplier: 0.25).isActive = true
但是你应该这样构造它:
let constraint = NSLayoutConstraint(item: view, attribute: .top, relatedBy: .equal, toItem: otherView, attribute: .centerY, multiplier: 0.25, constant: 1)
constraint.isActive = true
关于ios - 找不到属性的相关边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45086724/