我正在使用故事板构建自定义键盘 UI。应用程序运行良好,但我有如下约束错误。有人可以告诉我如何解决它吗?
这个错误似乎是由情节提要引起的,但我不知道到底是什么,也许我不应该强制设置高度和宽度限制。
平台信息 xcode:版本 14.3 (14E222b) 语言:swift
2023-04-22 15:44:03.092625+0800 bopomofoKeyboard[1983:45953] Failed to inherit CoreMedia permissions from 870: (null)
2023-04-22 15:44:03.167932+0800 bopomofoKeyboard[1983:45757] [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:0x6000010e0870 UIView:0x7fcdf830a9a0.width == 414 (active)>",
"<NSLayoutConstraint:0x6000010e45f0 'UIView-Encapsulated-Layout-Width' UIView:0x7fcdf830a9a0.width == 393 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000010e0870 UIView:0x7fcdf830a9a0.width == 414 (active)>
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.
我的代码是这样的
override func viewDidLoad() {
// Perform custom UI setup here
// disable autoresize
view.translatesAutoresizingMaskIntoConstraints = true
if(preferredInterfaceOrientationForPresentation.isPortrait) {
//set row landscape protrait height
RowA0.heightAnchor.constraint(equalToConstant: 45).isActive = true
RowA1.heightAnchor.constraint(equalToConstant: 50).isActive = true
RowA2.heightAnchor.constraint(equalToConstant: 50).isActive = true
RowA3.heightAnchor.constraint(equalToConstant: 50).isActive = true
RowA4.heightAnchor.constraint(equalToConstant: 45).isActive = true
RowB1.heightAnchor.constraint(equalToConstant: 50).isActive = true
RowB2.heightAnchor.constraint(equalToConstant: 50).isActive = true
RowB3.heightAnchor.constraint(equalToConstant: 50).isActive = true
RowC1.heightAnchor.constraint(equalToConstant: 50).isActive = true
RowC2.heightAnchor.constraint(equalToConstant: 50).isActive = true
ThirdKeyboardButton.heightAnchor.constraint(equalToConstant: 50).isActive = true
ShiftButton.heightAnchor.constraint(equalToConstant: 50).isActive = true
//change keyboard protrait hight
let heightconstraint = NSLayoutConstraint(item: self.view as Any,attribute: .height,relatedBy: .equal,toItem: nil,attribute: .notAnAttribute,multiplier: 0.0,
constant: 258) // Set custom height here
self.view.addConstraint(heightconstraint)
//change keyboard protrait width
let widthconstraint = NSLayoutConstraint(item: self.view as Any,attribute: .width,relatedBy: .equal,toItem: nil,attribute: .notAnAttribute,multiplier: 0.0,
constant: 414) // Set custom width here
self.view.addConstraint(widthconstraint)
}
if(preferredInterfaceOrientationForPresentation.isLandscape) {
//set row landscape landscape height
RowA0.heightAnchor.constraint(equalToConstant: 30).isActive = true
RowA1.heightAnchor.constraint(equalToConstant: 30).isActive = true
RowA2.heightAnchor.constraint(equalToConstant: 30).isActive = true
RowA3.heightAnchor.constraint(equalToConstant: 30).isActive = true
RowA4.heightAnchor.constraint(equalToConstant: 30).isActive = true
RowB1.heightAnchor.constraint(equalToConstant: 30).isActive = true
RowB2.heightAnchor.constraint(equalToConstant: 30).isActive = true
RowB3.heightAnchor.constraint(equalToConstant: 30).isActive = true
RowC1.heightAnchor.constraint(equalToConstant: 30).isActive = true
RowC2.heightAnchor.constraint(equalToConstant: 30).isActive = true
ThirdKeyboardButton.heightAnchor.constraint(equalToConstant: 30).isActive = true
ShiftButton.heightAnchor.constraint(equalToConstant: 30).isActive = true
//change keyboard landscape hight
let heightconstraint = NSLayoutConstraint(item: self.view as Any,attribute: .height,relatedBy: .equal,toItem: nil,attribute: .notAnAttribute,multiplier: 0.0,
constant: 170) // Set custom height here
self.view.addConstraint(heightconstraint)
//change keyboard landscape width
let widthconstraint = NSLayoutConstraint(item: self.view as Any,attribute: .width,relatedBy: .equal,toItem: nil,attribute: .notAnAttribute,multiplier: 0.0,
constant: 808) // Set custom width here
self.view.addConstraint(widthconstraint)
}
我也有故事板