Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MARK: Key broad behavior
- //Outlet
- //Action
- //Delegate
- func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
- NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.keyboardDidShowing), name: UIKeyboardDidShowNotification, object: nil)
- return true
- }
- func textFieldShouldEndEditing(textField: UITextField) -> Bool {
- NSNotificationCenter.defaultCenter().addObserver(self, selector:#selector(self.keyboardDidHiding), name: UIKeyboardDidHideNotification, object: nil)
- return true
- }
- //overide
- //method
- //selector
- func keyboardDidShowing(notification:NSNotification){
- print("keyboardDidShowing................")
- if let userInfo = notification.userInfo {
- let keyboardSize = userInfo[UIKeyboardFrameBeginUserInfoKey]?.CGRectValue().size
- //print(keyLastbound)
- //self.view.frame = CGRectMake(0, -110, 320, 460)
- UIView.animateWithDuration(0.3, animations: {() -> Void in
- var f = self.view.frame
- f.origin.y = -(keyboardSize?.height)!
- self.view.frame = f
- })
- }
- }
- func keyboardDidHiding(notification:NSNotification){
- print("keyboardDidHiding................")
- //self.view.frame = CGRectMake(0, 0, 320, 460)
- UIView.animateWithDuration(0.3, animations: {() -> Void in
- var f = self.view.frame
- f.origin.y = 0.0
- self.view.frame = f
- print("code goes on fine ..........")
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment