IOS questions about the keyboard masking editing area (uitextfiled/uitextview)

Source: Internet
Author: User
<span id="Label3"></p><p><p>Reference from: http://blog.csdn.net/windkisshao/article/details/21398521</p></p><p><p>1. Custom Methods for moving views</p></p><p><p>-(void) moveinputbarwithkeyboardheight: (float) _cgrectheight withduration: (nstimeinterval) _nstimeinterval;</p></p><p><p>2. Register for monitoring</p></p><p><p>Nsnotificationcenter *defaultcenter = [nsnotificationcenter defaultcenter];</p></p><p><p>[defaultcenter selector: @selector (keyboardwillshow:) name:uikeyboardwillshownotification object:nil];</p></p><p><p>[defaultcenter addobserver:self selector: @selector (keyboardwillhide:) name:uikeyboardwillhidenotification object: nil];</p></p><p><p>3. Implementation methods</p></p><p><p>-(void) keyboardwillshow: (nsnotification *) Notification {</p></p><p><p>Nsdictionary *userinfo = [notification userInfo];</p></p><p><p>nsvalue* avalue = [userInfo objectforkey:uikeyboardframeenduserinfokey];</p></p><p><p>CGRect keyboardrect = [avalue cgrectvalue];</p></p><p><p>Nsvalue *animationdurationvalue = [userInfo objectforkey:uikeyboardanimationdurationuserinfokey];</p></p><p><p>Nstimeinterval animationduration;</p></p><p><p>[animationdurationvalue getvalue:&animationduration];</p></p><p><p>If (nil==self.mytextview) Return;//self.edittextview is a control that is obscured by the keyboard</p></p><p><p>CGRect rect = self.myTextView.frame;</p></p><p><p>float texty = rect.origin.y + rect.size.height;</p></p><p><p>float bottomy = screenheight-texty;//gets The bottom border to the bottom of the distance screenheight is the height of the current device</p></p><p><p>If (bottomy >=keyboardrect.size.height) {//keyboard default height, if greater than this height, return directly</p></p><p><p>Return</p></p><p><p>}</p></p><p><p>float Movey = keyboardrect.size.height-bottomy;</p></p><p><p>[self Moveinputbarwithkeyboardheight:movey withduration:animationduration];</p></p><p><p>}</p></p><p><p></p></p><p><p>-(void) keyboardwillhide: (nsnotification *) Notification {</p></p><p><p>nsdictionary* UserInfo = [notification userInfo];</p></p><p><p>Nsvalue *animationdurationvalue = [userInfo objectforkey:uikeyboardanimationdurationuserinfokey];</p></p><p><p>Nstimeinterval animationduration;</p></p><p><p>[animationdurationvalue getvalue:&animationduration];</p></p><p><p>[self moveinputbarwithkeyboardheight:0.0 withduration:animationduration];</p></p><p><p>}</p></p><p><p></p></p><p><p>-(void) moveinputbarwithkeyboardheight: (float) _cgrectheight withduration: (nstimeinterval) _nstimeinterval{</p></p><p><p>CGRect rect1 = self.view.frame;</p></p><p><p>[UIView Beginanimations:nil context:null];</p></p><p><p>[UIView setanimationduration:_nstimeinterval];</p></p><p><p>RECT1.ORIGIN.Y =-_cgrectheight;//view Upward Movement</p></p><p><p>Self.view.frame = rect1;</p></p><p><p>[UIView commitanimations];</p></p><p><p>}</p></p><p><p>Test is used 4s real machine test, everything is perfect, but a few days ago colleagues with 6 test when found a problem, that is, when the editor can achieve the effect of the control, but found that the input of Chinese sometimes inexplicable can not knock out the chinese, there will be a series of characters, and delete when the character is deleted, Almost the more the more the Deletion. but the 4S has been tested many times without this problem. these days have been thinking about what caused this problem, looking to know the high people, pointing twos. thank you! (with the Uitextview)</p></p><p><p></p></p><p><p>IOS questions about the keyboard masking editing area (uitextfiled/uitextview)</p></p></span>

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.