Advertisement
redribben

tableview resize

Dec 11th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.45 KB | None | 0 0
  1. @objc func resizeSectionIndex(_ notification: Notification) {
  2.         let keyboardHeightInitial = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.height
  3.         let keyboardHeightFinal = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.height
  4.        
  5.         print("Initial height: \(keyboardHeightInitial)")
  6.         print("Final height: \(keyboardHeightFinal)")
  7.        
  8.         if notification.name == .UIKeyboardWillHide {
  9.             if keyboardHeightInitial != 0 && keyboardHeightInitial != keyboardHeightFinal {
  10.                 let keyboardHeightDifference = keyboardHeightFinal! - keyboardHeightInitial!
  11.                 tableView.frame.size.height = tableView.frame.size.height + keyboardHeightDifference
  12.                 let myint = 233
  13.                 return
  14.             }
  15.             tableView.frame.size.height = tableView.frame.size.height + keyboardHeightFinal!
  16.         }
  17.        
  18.         if notification.name == .UIKeyboardWillShow {
  19.             if keyboardHeightInitial != keyboardHeightFinal {
  20.                 let keyboardHeightDifference = keyboardHeightFinal! - keyboardHeightInitial!
  21.                 tableView.frame.size.height = tableView.frame.size.height - keyboardHeightDifference
  22.                 return
  23.             }
  24.             tableView.frame.size.height = tableView.frame.size.height - keyboardHeightFinal!
  25.         }
  26.         print(tableView.frame.size.height)
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement