Dynamically Retrieve keyboard height

Source: Internet
Author: User
// When there is input. The height of the keyboard changes dynamically. The height of Chinese input is different from that of English input. Therefore, you must change the position of the input box. # pragma mark-keyboardhight-(void) viewwillappear :( bool) animated {[self defined];}-(void) viewwilldisappear :( bool) animated {[[nsnotifcenter center defacenter center] removeobserver: Self];}-(void) registerforkeyboardconfigurations {// use nsicationicationcenter to publish the current [[nsicationicationcenter defacenter] addobserver: Self selector: @ selector (keyboardwasshown :) name: uikey Boarddidshownotification object: Nil]; // when using nsicationicationcenter center to hide [nsnotificationcenter defacenter center] addobserver: Self selector: @ selector (keyboardwillbehidden :) name: jsonobject: Nil];} // calculate the height of the keyboard when it appears. Used to display location-(void) keyboardwasshown :( nsnotification *) anotification {nsdictionary * info = [anotification userinfo] in the input box; // kbsize is the size (with width and height) cgsize kbsize = [[info objectforkey: uikeyboardframeenduserinfokey] cgrectvalue]. size; // obtain the nslog (@ "hight_hitht: % F", kbsize. height); If (kbsize. height = 216) {keyboardhight = 0;} else {keyboardhight = 36; // 252-216 two different heights of the system keyboard} // input box position animation loading [self be Gainmoveupanimation: keyboardhight];} // when the keyboard is hidden-(void) keyboardwillbehidden :( nsnotification *) anotification {// do something} // (textview) before the keyboard starts inputting. -(Void) textviewdidbeginediting :( uitextview *) textview {nslog (@ "gegin Animation"); sendmsgtextview = textview; resultcommunitytableview. frame = cgrectmake (0, 36,320,150); // animated loading [self ainainmoveupanimation: 0.0];} // disable the keyboard (textview) for changing the row. Hide the keyboard-(bool) textview :( uitextview *) textview shouldchangetextinrange :( nsange) range replacementtext :( nsstring *) text {resultcommunitytableview. frame = cgrectmake (0, 36,320,376); If ([text isequaltostring: @ "\ n"]) {[textview resignfirstresponder]; return no;} return yes ;} // call the animation when the input ends (press the button. Background. Move all input boxes)-(void) textviewdidendediting :( uitextview *) textview {nslog (@ "tabtabtab"); [self endeditanimation]; // release [nsicationicationcenter defacenter] removeobserver: self name: uikeyboardwillshownotification object: Nil]; [[nsicationcenter center defacenter center] removeobserver: Self name: icationobject: Nil];} // judge the current input method-(void) textviewdidchangeselection :( uitextview *) textview {nslog (@ "Wewe: % @", [[uitextinputmode currentinputmode] primarylanguage]); /* If ([[uitextinputmode currentinputmode] primarylanguage] = @ "En-us") {nslog (@ "En-us ");} else {nslog (@ "ZH-Hans ");}*/}

Dynamically Retrieve keyboard height

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.