-(void) viewdidload{[Super Viewdidload]; Increased monitoring, when the keyboard appears or changes to receive messages <pre name= "code" class= "OBJC" ><p style= "margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; Color:rgb (61, 29, 129); " ><span style= "Color:rgb (0, 0, 0); > [[</span><span style= "Color:rgb (112, 61, 170); >nsnotificationcenter</span><span style= "Color:rgb (0, 0, 0); > </span>defaultcenter<span style= "color:rgb (0, 0, 0); ] </span>addobserver<span style= "Color:rgb (0, 0, 0); >:</span><span style= "Color:rgb (187, 44, 162); >self</span></p><p style= "margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " > <span style= "Color:rgb (61, 29, 129); >selector</span>:<span style= "Color:rgb (187, 44, 162);"> @selector </span> (keyboarddidshow:) </p><p style=" margin-top:0px; margin-bottom:0px; Font-size: 13px; Font-family:menlo; " > <span style= "Color:rgb (61, 29, 129);" >name</span>:<span style= "Color:rgb (112, 61, 170); >uikeyboardwillshownotification</span></p><p style= "margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " > <span style= "Color:rgb (61, 29, 129); >object</span>:<span style= "Color:rgb (187, 44, 162); >nil</span>];</p>
Increased monitoring, when the key exits when the message is received <p style= "margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; Color:rgb (61, 29, 129); " ><span style= "Color:rgb (0, 0, 0); > [[</span><span style=] Color:rgb (112, 61, 170); " >nsnotificationcenter</span><span style= "Color:rgb (0, 0, 0); > </span>defaultcenter<span style= "color:rgb (0, 0, 0); ] </span>addobserver<span style= "Color:rgb (0, 0, 0); >:</span><span style= "Color:rgb (187, 44, 162); >self</span></p><p style= "margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " > <span style= "Color:rgb (61, 29, 129); >selector</span>:<span style= "Color:rgb (187, 44, 162); > @selector </span> (keyboarddidhide:) </p><p style= "margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " > <span style= "Color:rgb (61, 29, 129);" >name</span>:<span style= "Color:rgb (112, 61, 170); >uikeyboardwillhidenotification</span></p><p style= "margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " > <span style= "Color:rgb (61, 29, 129); >object</span>:<span style= "Color:rgb (187, 44, 162); >nil</span>];</p>
}
Call <p style= "margin-top:0px when the keyboard appears or changes; margin-bottom:0px; font-size:13px; Font-family:menlo; " >-(<span style= "font-variant-ligatures:no-common-ligatures; color: #bb2ca2" >void</span>) Keyboarddidshow: (<span style= "font-variant-ligatures:no-common-ligatures; Color: #703daa ">NSNotification</span> *) notification{</p><p style=" margin-top:0px; margin-bottom : 0px; font-size:13px; Font-family:menlo; " > <span style= "font-variant-ligatures:no-common-ligatures; Color: #703daa ">NSDictionary</span> *userinfo = [notification <span style=" Font-variant-ligatures: No-common-ligatures; Color: #3d1d81 ">userinfo</span>];</p><p style=" margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; Color:rgb (112, 61, 170); " ><span style= "font-variant-ligatures:no-common-ligatures; Color: #000000 "> </span>cgsize<span style=" font-variant-ligatures:no-common-ligatures; ColoR: #000000 "> keyboardsize = [[UserInfo </span><span style=" font-variant-ligatures:no-common-ligatures; Color: #3d1d81 ">objectforkey</span><span style=" font-variant-ligatures:no-common-ligatures; Color: #000000 ">:</span>uikeyboardframebeginuserinfokey<span style=" Font-variant-ligatures: No-common-ligatures; Color: #000000 ";] </span><span style=" font-variant-ligatures:no-common-ligatures; Color: #3d1d81 ">cgrectvalue</span><span style=" font-variant-ligatures:no-common-ligatures; Color: #000000 ">].</span>size<span style=" font-variant-ligatures:no-common-ligatures; Color: #000000 ">;</span></p><p style=" margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " > <span style= "font-variant-ligatures:no-common-ligatures; Color: #4f8187 ">_keyBoardHeight</span> = Keyboardsize.<span style=" Font-variant-ligatures: No-common-ligatures; Color: #703daa ">heigHt</span>;</p><p style= "margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; Color:rgb (49, 89, 93); " ><span style= "font-variant-ligatures:no-common-ligatures; Color: #000000 > [</span><span style=] font-variant-ligatures:no-common-ligatures; color: # BB2CA2 ">self</span><span style=" font-variant-ligatures:no-common-ligatures; Color: #000000 "> </span>changeviewybyshow<span style=" font-variant-ligatures:no-common-ligatures; Color: #000000 ">];</span></p><p style=" margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " >}</p><p style= "margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " ></p><pre name= "code" class= "OBJC" ><pre name= "code" class= "OBJC" >//called when the keyboard is hidden
<p style= "margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " >-(<span style= "font-variant-ligatures:no-common-ligatures; color: #bb2ca2" >void</span>) Keyboarddidhide: (<span style= "font-variant-ligatures:no-common-ligatures; Color: #703daa ">NSNotification</span> *) notification{</p><p style=" margin-top:0px; margin-bottom : 0px; font-size:13px; Font-family:menlo; Color:rgb (79, 129, 135); " ><span style= "font-variant-ligatures:no-common-ligatures; Color: #000000 "> </span>_keyboardheight<span style=" Font-variant-ligatures: No-common-ligatures; Color: #000000 "> = </span><span style=" font-variant-ligatures:no-common-ligatures; Color: #272ad8 ">0</span><span style=" font-variant-ligatures:no-common-ligatures; Color: #000000 ">;</span></p><p style=" margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; Color:rgb (49, 89, 93); " ><span sTyle= "Font-variant-ligatures:no-common-ligatures; Color: #000000 > [</span><span style=] font-variant-ligatures:no-common-ligatures; color: # BB2CA2 ">self</span><span style=" font-variant-ligatures:no-common-ligatures; Color: #000000 "> </span>changeviewybyhide<span style=" font-variant-ligatures:no-common-ligatures; Color: #000000 ">];</span></p><p style=" margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " >}</p>
<p style= "margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; Color:rgb (120, 73, 42); " > #pragma mark-private methods</p><p style= "margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " >-(<span style= "font-variant-ligatures:no-common-ligatures; color: #bb2ca2" >void</span>) Changeviewybyshow{</p><p style= "margin-top:0px; margin-bottom:0px; font-size:13px; font-family:menlo; Color:rgb (61, 29, 129); " ><span style= "font-variant-ligatures:no-common-ligatures; Color: #000000 > [</span><span style=] font-variant-ligatures:no-common-ligatures; color: # 703daa ">uiview</span><span style=" font-variant-ligatures:no-common-ligatures; Color: #000000 "> </span>animatewithduration<span style=" font-variant-ligatures:no-common-ligatures; Color: #000000 ">:</span><span style=" font-variant-ligatures:no-common-ligatures; Color: #272ad8 ">0.2</SPAN><span style= "font-variant-ligatures:no-common-ligatures; Color: #000000 "> </span>animations<span style=" font-variant-ligatures:no-common-ligatures; Color: #000000 ">:^{</span></p><p style=" margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " > <span style= "font-variant-ligatures:no-common-ligatures; Color: #703daa ">CGRect</span> rect = <span style=" font-variant-ligatures:no-common-ligatures; Color: #bb2ca2 ">self</span>.<span style=" font-variant-ligatures:no-common-ligatures; Color: #703daa ">view</span>.<span style=" font-variant-ligatures:no-common-ligatures; Color: #703daa ">frame</span>;</p><p style=" margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " > Rect.<span style= "font-variant-ligatures:no-common-ligatures; Color: #703daa ">origin</span>.<span style=" Font-variant-ligaTures:no-common-ligatures; Color: #703daa ">y</span>-= <span style=" font-variant-ligatures:no-common-ligatures; Color: #bb2ca2 ">self</span>.<span style=" font-variant-ligatures:no-common-ligatures; Color: #4f8187 ">keyboardheight</span>;</p><p style=" margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " > <span style= "font-variant-ligatures:no-common-ligatures; Color: #bb2ca2 ">self</span>.<span style=" font-variant-ligatures:no-common-ligatures; Color: #703daa ">view</span>.<span style=" font-variant-ligatures:no-common-ligatures; Color: #703daa ">frame</span> = rect;</p><p style=" margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " > }];</p><p style= "margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " >}</p>
<p style= "margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " >-(<span style= "font-variant-ligatures:no-common-ligatures; color: #bb2ca2" >void</span>) Changeviewybyhide{</p><p style= "margin-top:0px; margin-bottom:0px; font-size:13px; font-family:menlo;" > <span style= "font-variant-ligatures:no-common-ligatures; Color: #703daa ">CGRect</span> rect = <span style=" font-variant-ligatures:no-common-ligatures; Color: #bb2ca2 ">self</span>.<span style=" font-variant-ligatures:no-common-ligatures; Color: #703daa ">view</span>.<span style=" font-variant-ligatures:no-common-ligatures; Color: #703daa ">frame</span>;</p><p style=" margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " > Rect.<span style= "font-variant-ligatures:no-common-ligatures; Color: #703daa ">origin</span>.<span style=" Font-variant-ligatures:no-common-ligAtures; Color: #703daa ">y</span> = <span style=" font-variant-ligatures:no-common-ligatures; Color: #272ad8 ">64</span>;</p><p style=" margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " > <span style= "font-variant-ligatures:no-common-ligatures; Color: #bb2ca2 ">self</span>.<span style=" font-variant-ligatures:no-common-ligatures; Color: #703daa ">view</span>.<span style=" font-variant-ligatures:no-common-ligatures; Color: #703daa ">frame</span> = rect;</p><p style=" margin-top:0px; margin-bottom:0px; font-size:13px; Font-family:menlo; " >}</p>
iOS dev-get iOS soft keyboard height