簡體   English   中英

iOS和Swift 4中自定義鍵盤的高度

[英]Height of custom keyboard in iOS and Swift 4

如何獲得iOS給自定義鍵盤的視圖高度?

我目前正在為iPhone 8 Plus手動設置鍵盤界面:

var keyboardHeight: CGFloat {
    return UIScreen.main.bounds.height > UIScreen.main.bounds.width ? 226 : 162
}

如何以編程方式獲取所有尺寸類別的鍵盤高度?

常見的方法是: 聽鍵盤通知並對其進行響應
隨通知一起發送的userInfo詞典的endFrame鍵包含正確的鍵盤大小。 我還要考慮到最終的accessoryInputView

嘗試這個

override func viewDidLoad() {
    super.viewDidLoad()

    let desiredHeight: CGFloat =  500
    let heightConstraint = NSLayoutConstraint(item: view, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: desiredHeight)
    view.addConstraint(heightConstraint)

    self.nextKeyboardButton.addTarget(self, action: #selector(handleInputModeList(from:with:)), for: .allTouchEvents)

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM