-(Void) viewdidload {[Super viewdidload]; // specify itself as the proxy _ test_uitextfield.delegate = self; // register the keyboard response event method [_ test_uitextfield addtarget: Self action: @ selector (hiddenkeyboard :) forcontrolevents: Success]; // Add a gesture. Click the operation to close the keyboard in other areas of the screen * gesture = [[uitapgesturerecognizer alloc] initwithtarget: Self action: @ selector (hidenkeyboard)]; gesture. numberoftapsrequired = 1; [self. view addgesturerecognizer: gesture];} // Method for responding to the return button on the keyboard-(ibaction) hiddenkeyboard :( uitextfield *) sender {If (sender = _ test_uitextfield) {[_ test_uitextfield resignfirstresponder]; [self resumeview] ;}// Method for hiding the keyboard-(void) hidenkeyboard {[_ test_uitextfield resignfirstresponder]; [self resumeview];} // restore the original view location-(void) resumeview {[self changekeyboard: 0.0f];} // protocol method of uitextfield, listen when editing-(bool) authorization :( uitextfield *) textfield {[self changekeyboard:-180.0f]; return yes;}-(void) changekeyboard :( float) h {nstimeinterval animationduration = 0.30f; [uiview beginanimations: @ "resizeforkeyboard" context: Nil]; [uiview setanimationduration: animationduration]; float width = self. view. frame. size. width; float Height = self. view. frame. size. height; // The height of H to move up or down. cgrect rect = cgrectmake (0.0f, H, width, height); self. view. frame = rect; [uiview commitanimations];}
:
Source code: Download