键盘隐藏 UITextField。怎么解决这个问题呢?
我有一个位于屏幕底部的文本字段。当我开始编辑时,键盘会出现并隐藏文本字段。
谁能建议如何解决这个问题?
I have a textField which is at bottom of the screen. When I begin editing, the keyboard appears and hides the textField.
Can anyone suggest how to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
通常,您会将内容放在滚动视图中,并在键盘出现时向上移动滚动视图。那里有很多教程,所以谷歌一下。
此处
就是其中之一。Generally you would put your content in a scroll view and move your scroll view up when the keyboard appears. There are many tutorials out there so google them.
Here
is one of them.您可以在两个不同的方法中使用以下代码,在编辑开始和结束时调用它,上下移动视图,(只需更改
yourView.frame.origin.y-100
中减去的值即可根据您的需要进行调整)You can use following code in two diffrent method, call it when editing began and end, to move your view up and down,(just change the valuew that is been subtracted in
yourView.frame.origin.y-100
to adjust according to your need)请参阅此代码片段。并使用一个 UIButton 来关闭 UIKeyboard。
See this code snippet. And use one UIButton to dismiss UIKeyboard.
当您点击文本字段键盘向上时,您的文本字段将隐藏在其旁边。所以你需要什么,你需要让你的视图不键盘重新签名是一个解决方案。所以为了让您查看使用
希望它对您有帮助。
When you tap on textField keyboard up then your textField hide by it. so waht you need, you need to make your view up not keyboardresign is a solution. so for making you view up use
hope it helps you.
我使用自动布局约束来解决这个问题。我将约束作为一种属性,并在键盘出现/消失时使用它。我只需将文本字段上方的视图移出屏幕,然后将文本字段移至顶部。完成编辑后,我通过约束将它们移动到原始位置。
I use auto layout constraint to solve this problem. I hold constraint as a property, and play with it when keyboard appears / disappears. I simply move views above the textfield out of screen, and textfield to the top. After finishing edit, I move them by the constraint to their original position.