[Code Note] iOS-only allows textField to use keyboard notifications, ios-textfield
Code:
# Import "ViewController. h "@ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // Add a keyboard event for textField [[nsnotifcenter center defacenter center] addObserver: self selector: @ selector (addKeyboardNoti) name: jsonobject: nil]; [[nsicationicationcenter defacenter center] addObserver: self selector: @ selector (removeKeyboardNoti) name: UITextFieldTextDidEndEditingNotification object: nil] ;}# pragma-mark-keyboard javasicatin // keyboard event-(void) keyboardWillShow :( NSNotification *) notification {NSDictionary * info = [notification userInfo]; // The keyboardHeight is the keyboard height CGSize keyboardSize = [[info objectForKey: UIKeyboardFrameEndUserInfoKey] CGRectValue]. size; [self animateViewWithKeyboardHeight: keyboardSize. height];}-(void) keyboardWillHide :( NSNotification *) notification {[self defined: 0.0];}-(void) Updated :( CGFloat) keyboardHeight {NSTimeInterval animationDuration = 0.3f; CGFloat height = self. view. bounds. size. height; CGFloat width = self. view. bounds. size. width; CGFloat topSize = 0.0; CGFloat viewH = self. view. frame. size. height-64; CGFloat deviceHeight = [UIScreen mainScreen]. bounds. size. height; CGFloat animateH = deviceHeight-viewH-keyboardHeight; if (animateH> = 0) {topSize = 0; CGRect toRect = CGRectMake (0, topSize, width, height); self. view. frame = toRect;} else {topSize = animateH; CGRect toRect = CGRectMake (0, topSize, width, height); [UIView animateWithDuration: animationDuration animations: ^ {self. view. frame = toRect ;}] ;}# pragma-mark-UITextFieldText Notification // Add a keyboard event-(void) addKeyboardNoti {NSLog (@ "------ addKeyboardNoti -------"); [[nsicationcenter center defacenter center] addObserver: self selector: @ selector (keyboardWillShow :) name: jsonobject: nil]; [[nsicationicationcenter defacenter center] addObserver: self selector: @ selector (handler :) name: jsonobject: nil] ;}// remove Keyboard Events-(void) removeKeyboardNoti {NSLog (@ "------ removeKeyboardNoti ---------"); [[nsicationicationcenter defacenter center] removeObserver: self name: UIKeyboardWillShowNotification object: nil]; [[nsicationcenter center defacenter center] removeObserver: self name: icationobject: nil];}-(void) didreceivemorywarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} @ end