Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
OrganizationAdvent CalendarQiitadon (β)
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?


More than 1 year has passed since last update.

キーボードが表示された時に UITextView の下位置を調整しようとした際に
最初は cgSizeValue で height を取得していたため位置の調整に失敗していた。
cgRectValue で取得でないとダメ。念の為取得結果を検証してみました。


@objc func keyboardWillShow(notification: NSNotification) {
    if let userInfo = notification.userInfo {
        if let keyboardFrame = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
       self.textViewBottom.constant = keyboardFrame.cgRectValue.height

            let keyboardRect = keyboardFrame.cgRectValue
            let keyboardSize = keyboardFrame.cgSizeValue
            let keyboardPoint = keyboardFrame.cgPointValue

            print("self.view.frame.size[\(self.view.frame.size)] self.view.frame.origin[\(self.view.frame.origin)]")
            print("keyboardFrame.cgRectValue.size[\(keyboardRect.size)] cgRectValue.cgRectValue.origin[\(keyboardRect.origin)]")

iPhone8 で実行

self.view.frame.size[(375.0, 667.0)] self.view.frame.origin[(0.0, 0.0)]
keyboardFrame.cgRectValue.size[(375.0, 260.0)] cgRectValue.cgRectValue.origin[(0.0, 407.0)]
keyboardFrame.cgSizeValue[(0.0, 407.0)]
keyboardFrame.cgPointValue[(0.0, 407.0)]

cgSizeValue は cgPointValue の値と同じなってしまっているようで、バグっぽいですね。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away