Lotheve的专栏

– (void)viewDidLoad{[super viewDidLoad];//增加监听,当键盘出现或改变时收出消息<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> //增加监听,,当键退出时收出消息<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>}//当键盘出现或改变时调用<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>)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">//当键盘隐藏时调用<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>

去陌生的街角,去做一切我们曾经或现在也很想做的事情,

Lotheve的专栏

相关文章:

你感兴趣的文章:

标签云: