键盘出现时如何滚动查看? [英] How to scroll view up when keyboard appears?

查看:93
本文介绍了键盘出现时如何滚动查看?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题一再被问到,但似乎没有什么对我有用。大多数解决方案都是过时的,其余的是非常庞大的代码块,比实际的项目编码大十倍。我有几个UITextField垂直排列,但当键盘启动编辑一个时,它会覆盖文本字段。我想知道是否有一种简单的初学者方式来滚动视图,然后在编辑开始和结束时退回?

I know that this question has been asked over and over again, but nothing seems to be working for me. Most of the solutions around are pretty out of date, and the rest are incredibly huge blocks of code that are ten times larger then the actual projects coding. I have a few UITextFields lined up vertically, but when the keyboard launches to edit one, it covers up the text field. I was wondering if there is a simple beginner way to scroll the view up, and then back down when the editing starts and ends?

谢谢。

推荐答案

我使用键盘通知和当前第一响应者的检测,使用滚动和非滚动视图的解决方案,但有时我使用这个简单的解决方案:简单的方法是通过文本字段委托的 textViewDidBeginEditing:方法检测打开的键盘并移动整个视图。最简单的方法是将 self.view.bounds.origin.y 更改为-100(或其他)。使用相应的 textViewShouldEndEditing:方法将其设置为相反的方式,在本例中为100。更改边界是一个相对过程。更改后,帧移动但边界原点仍然为零。

I have made solutions that work with scroll and non-scroll views using keyboard notification and a detection of the current first responder, but sometimes I use this trivial solution instead: The simple way is to detect the opening keyboard via the text field delegate's textViewDidBeginEditing: method and to move the entire view up. The easiest way to do this is with something along the lines of changing self.view.bounds.origin.y to -100 (or whatever). Use the corresponding textViewShouldEndEditing: method to set it to the opposite, which is 100 in this case. Changing bounds is a relative procedure. After changing it the frame is moved but the bounds origin is still zero.

这篇关于键盘出现时如何滚动查看?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆