custom keyboard landscape don't show right

Viewed 15

when I want to active landscape for my custom keyboard, I set new constraint for them. but I don't know why the landscape isn't been show rightly. the protrait is good, but the landscape is not. some one can help?

Xcode Version: Version 13.4.1 (13F100) Swift Version: 5 LandScape is not right

keyboard Landscape

override func viewDidLoad() {
  super.viewDidLoad()
    // Perform custom UI setup here
    shiftStatus = 0
    deleteletters = 0// disable autoresize
    view.translatesAutoresizingMaskIntoConstraints = false
   

    
    
    
    
  if(preferredInterfaceOrientationForPresentation.isPortrait)  {
   //set row 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
    
    
   //change keybaord protrait hight
  let heightconstraint = NSLayoutConstraint(item: self.view as Any,
                                               attribute: .height,
                                               relatedBy: .equal,
                                               toItem: nil,
                                               attribute: .notAnAttribute,
                                               multiplier: 0.0,
                                               constant: 255) // Set custom height here
                                               self.view.addConstraint(heightconstraint)
        
     //change keybaord protrait width
  let widthconstraint = NSLayoutConstraint(item: self.view as Any,
                                               attribute: .width,
                                               relatedBy: .equal,
                                               toItem: nil,
                                               attribute: .notAnAttribute,
                                               multiplier: 0.0,
                                               constant: 428) // Set custom height here
                                               self.view.addConstraint(widthconstraint)
  }
  if(preferredInterfaceOrientationForPresentation.isLandscape) {
  
         //set row 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
   //change keybaord 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 keybaord landscape width
  let widthconstraint = NSLayoutConstraint(item: self.view as Any,
                                               attribute: .width,
                                               relatedBy: .equal,
                                               toItem: nil,
                                               attribute: .notAnAttribute,
                                               multiplier: 0.0,
                                               constant: 838) // Set custom height here
                                               self.view.addConstraint(widthconstraint)
  }

}
0 Answers
Related