redribben icon

tableview resize

redribben | PRO | 12/12/17 12:58:12 AM UTC | 0 ⭐ | 297 👁️ | Never ⏰ | []
Swift |

1.45 KB

|

None

|

0 👍

/

0 👎

@objc func resizeSectionIndex(_ notification: Notification) {
        let keyboardHeightInitial = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.height
        let keyboardHeightFinal = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.height
        
        print("Initial height: \(keyboardHeightInitial)")
        print("Final height: \(keyboardHeightFinal)")
        
        if notification.name == .UIKeyboardWillHide {
            if keyboardHeightInitial != 0 && keyboardHeightInitial != keyboardHeightFinal {
                let keyboardHeightDifference = keyboardHeightFinal! - keyboardHeightInitial!
                tableView.frame.size.height = tableView.frame.size.height + keyboardHeightDifference
                let myint = 233
                return
            }
            tableView.frame.size.height = tableView.frame.size.height + keyboardHeightFinal!
        }
        
        if notification.name == .UIKeyboardWillShow {
            if keyboardHeightInitial != keyboardHeightFinal {
                let keyboardHeightDifference = keyboardHeightFinal! - keyboardHeightInitial!
                tableView.frame.size.height = tableView.frame.size.height - keyboardHeightDifference
                return
            }
            tableView.frame.size.height = tableView.frame.size.height - keyboardHeightFinal!
        }
        print(tableView.frame.size.height)
    }

Comments