Text Box occlusion by keyboard

Source: Internet
Author: User
-(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.