iOS中键盘和UIVew之间有空格 [英] Blank space coming between keyboard and UIVew in iOS

查看:71
本文介绍了iOS中键盘和UIVew之间有空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于标签栏控制器的应用程序,并且正在使用IQKeyboardManager处理类似表单的内容.

I have a tab bar controller-based application and I am using IQKeyboardManager to handle form-like stuff.

第1步:在UIView的底部带有UITextView的选项卡栏控制器.查看图片1.

Step 1: Tab bar controller with bottom a UITextView inside a UIView. Check Image 1.

第2步:当我单击UITextView时,出现键盘,但由于选项卡栏而出现空白.我试图删除IQKeyboardManager,但是它仍然会发生,因此可以确认这不是IQKeyboardManager的问题.这是由于标签栏控制器引起的.

Step2: When I click on UITextView, the keyboard appears but a blank space is appearing due to the tab bar. I have tried to remove IQKeyboardManager but it still occurs, so it is confirmed that it is not the issue of IQKeyboardManager. It is an issue due to the tab bar controller.

如何删除该间距?

推荐答案

您是正确的.空格是由标签栏引起的.通过添加当您收到键盘时应该出现的额外空间来覆盖视图中的y位置,而不是在viewDidLoad或其他任何地方,以覆盖视图中的y位置,因为它将被隐藏在选项卡栏的后面.然后,您需要在用户完成使用键盘操作时删除该增加的值,以将其设置回正常状态.例如.

You are correct. The blank space is caused by the tab bar. Override the y position in the view by adding the additional space when you receive keyboard should appear and not in your viewDidLoad or any place else because it will then be hidden behind the tab bar. Then you need to set it back to normal by removing that added value when the user is finished using the keyboard. eg.

// Declaration
var tabBarHeight : CGFloat = 0.0
// viewDidLoad
tabBarHeight = tabBarController?.tabBar.frame.size.height
// When the user begins using the keyboard move the view containing the textfield
yourView.frame.origin.y = (tabBarController?.tabBar.frame.origin.y + tabBarHeight )
// When the user finishes using the keyboard
yourView.frame.origin.y = (tabBarController?.tabBar.frame.origin.y - tabBarHeight )

如果有约束,则需要进行调整.好的答案在这里:

If you have constraints, you will need to adjust them. Good answer here:

https://stackoverflow.com/a/27870216/4008175

此答案将帮助您聆听键盘的激活和停用时间:

This answer will assist you in listening to when the keyboard has been activated and deactivated:

https://stackoverflow.com/a/27087733/4008175

祝你好运!

这篇关于iOS中键盘和UIVew之间有空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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