0

i am use storyboard to build a custom keyboard UI. app working well,but i have a constraints error as below. somebody can tell me how could i fix it?

this error seems like cause by the storyboard, but i cant tell what exactly it is, maybe i should not force to set the height and width contraints.

platform info xcode: Version 14.3 (14E222b) language: 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.

and my code like this

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)
           }

and i have a storyboard too

enter image description here

2
  • You seem to be assuming the device is 414 points wide as you set an explicit width constraint at that size. The iPhone 6/7/8 plus devices have a width of 414 points. The constraint error shows a conflicting width of 393 points. That is the width of an iPhone 14 pro. You need to make your keyboard and the keys support quite a wide range of widths for different device types (especially if you need to support iPad). Commented Apr 22, 2023 at 8:59
  • i got it, sure, i just swith to iphone 14 developing now, thx, let me try Commented Apr 22, 2023 at 9:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.