Guest User

Untitled

a guest
Dec 15th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. //MARK: Key broad behavior
  2.  
  3. //Outlet
  4. //Action
  5. //Delegate
  6. func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
  7. NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.keyboardDidShowing), name: UIKeyboardDidShowNotification, object: nil)
  8. return true
  9. }
  10.  
  11. func textFieldShouldEndEditing(textField: UITextField) -> Bool {
  12. NSNotificationCenter.defaultCenter().addObserver(self, selector:#selector(self.keyboardDidHiding), name: UIKeyboardDidHideNotification, object: nil)
  13. return true
  14. }
  15. //overide
  16. //method
  17. //selector
  18. func keyboardDidShowing(notification:NSNotification){
  19. print("keyboardDidShowing................")
  20. if let userInfo = notification.userInfo {
  21. let keyboardSize = userInfo[UIKeyboardFrameBeginUserInfoKey]?.CGRectValue().size
  22. //print(keyLastbound)
  23. //self.view.frame = CGRectMake(0, -110, 320, 460)
  24. UIView.animateWithDuration(0.3, animations: {() -> Void in
  25.  
  26. var f = self.view.frame
  27. f.origin.y = -(keyboardSize?.height)!
  28. self.view.frame = f
  29.  
  30. })
  31. }
  32. }
  33. func keyboardDidHiding(notification:NSNotification){
  34. print("keyboardDidHiding................")
  35.  
  36. //self.view.frame = CGRectMake(0, 0, 320, 460)
  37.  
  38. UIView.animateWithDuration(0.3, animations: {() -> Void in
  39.  
  40. var f = self.view.frame
  41. f.origin.y = 0.0
  42. self.view.frame = f
  43. print("code goes on fine ..........")
  44. })
  45. }
Advertisement
Add Comment
Please, Sign In to add comment