This article describes a simple and practical small method.
I think some of the effects of landing should not be unfamiliar to everyone.
Let's introduce the implementation of the keyboard pop-up TextField accompanying the keyboard movement when you start typing TextField text.
Take a look at the demo effect first
We are bound by the Textfiel. The constraint content is as follows??
After the constraint is over, we need to do a very important thing is to drag the bottom constraint of the TextField to the appropriate code area.
The content is as follows??
By doing this, we can implement the content of the response through the code.
The implementation code is as follows:
viewcontroller.m//CX textfiled Implementation of keyboard movement////Created by Ma C on 16/3/31.//Copyright? 2016 Xubaoaichiyu. All rights reserved.//#import "ViewController.h" @interface Viewcontroller () @property (weak, nonatomic) Iboutlet Nslayoutconstraint *bottomspace; @end @implementation viewcontroller-(void) viewdidload {[Super viewdidload]; CV notification [[Nsnotificationcenter defaultcenter]addobserver:self selector: @selector ( Keyboardwillchangeframenotification:) name:uikeyboardwillchangeframenotification Object:nil];} -(void) Keyboardwillchangeframenotification: (nsnotification *) note{//Get keyboard hungry frame cgrect frmae = [Note.userinfo[uikey Boardframeenduserinfokey] Cgrectvalue]; Let textfiled the bottom of the screen height minus the top of the keyboard Y value can//note here do not make it equal to the height of the keyboard, because the height of the dead, will cause the keyboard down, the TextField did not go down the results. Self.bottomSpace.constant = [UIScreen mainscreen].bounds.size.height-frmae.origin.y; Gets the animation time of the keyboard so that the TextField is consistent with the shape of the keyboard cgfloat interval = [Note.userinfo[uikeyboardanimationdurationuserinfokey] Doublevalue]; Animate the text [UIView animatewithduration:interval animations:^{//Note here is not a change in value, the value has been changed before,//what needs to be done here is to force the cloth Bureau [Self.view Layoutifneeded]; }]; }-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (uievent *) event{[Self.view Endediting:yes]; } @end
IOS TextField Companion Keyboard move