iOS Development Ui--keyboard pop-up screen move up

Source: Internet
Author: User
<span id="Label3"></p> <code><code>平时在开发中,当有输入框时,弹出的键盘有时会遮挡住下方的屏幕,为此我们可以在对输入框进行操作时使屏幕上移,避免下方屏幕被遮挡。(也可以使用ScrollView进行滑动。)</code></code><code><code>#pragma mark - 屏幕上弹</code></code> <code><code>-(</code></code> <code><code>void</code></code> <code><code>)textFieldDidBeginEditing:(UITextField *)textField</code></code> <code><code>{</code></code> <code><code>    </code></code> <code><code>//键盘高度216</code></code> <code><code>    </code></code><code><code>    </code></code> <code><code>//滑动效果(动画)</code></code> <code><code>    </code></code> <code><code>NSTimeInterval animationDuration = 0.30f;</code></code> <code><code>    </code></code> <code><code>[UIView beginAnimations:@</code></code> <code><code>"ResizeForKeyboard"</code></code><code><code>context:nil];</code></code> <code><code>    </code></code> <code><code>[UIView setAnimationDuration:animationDuration];</code></code> <code><code>    </code></code><code><code>    </code></code> <code><code>//将视图的Y坐标向上移动,以使下面腾出地方用于软键盘的显示</code></code> <code><code>    </code></code> <code><code>self.view.frame = CGRectMake(0.0f, -100.0f, self.view.frame.size.width, self.view.frame.size.height);</code></code> <code><code>//64-216</code></code> <code><code>        </code></code><code><code>    </code></code> <code><code>[UIView commitAnimations];</code></code> <code><code>}</code></code><code><code>#pragma mark -屏幕恢复</code></code> <code><code>-(</code></code> <code><code>void</code></code> <code><code>)textFieldDidEndEditing:(UITextField *)textField</code></code> <code><code>{</code></code> <code><code>    </code></code> <code><code>//滑动效果</code></code> <code><code>    </code></code> <code><code>NSTimeInterval animationDuration = 0.30f;</code></code> <code><code>    </code></code> <code><code>[UIView beginAnimations:@</code></code> <code><code>"ResizeForKeyboard"</code></code><code><code>context:nil];</code></code> <code><code>    </code></code> <code><code>[UIView setAnimationDuration:animationDuration];</code></code> <code><code>    </code></code><code><code>    </code></code> <code><code>//恢复屏幕</code></code> <code><code>    </code></code> <code><code>self.view.frame = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.height);</code></code> <code><code>//64-216</code></code> <code><code>        </code></code><code><code>    </code></code> <code><code>[UIView commitAnimations];</code></code> <pre class="brush:cpp;toolbar: true; auto-links: false;"><pre class="brush:cpp;toolbar: true; auto-links: false;"><br></pre></pre> <p><p><br></p></p><p><p>iOS Development Ui--keyboard pop-up screen move up</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.