Blank space coming between keyboard and UIVew in iOS

纵然是瞬间 提交于 2020-12-06 05:41:42

问题


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

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

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.

How to remove that spacing?


回答1:


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

Good luck!



来源:https://stackoverflow.com/questions/44174160/blank-space-coming-between-keyboard-and-uivew-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!