I have been using IQKeyboardManager
to controller the keyboard in my app. It works fine, except with UISearchBar. How do I make it work with UISearchBar?

- 55,884
- 29
- 169
- 223

- 14,534
- 25
- 99
- 199
4 Answers
Working with UISearchBar is explicitly disabled on IQKeyboardManager.
You should modify -(BOOL)isSearchBarTextField
method to return NO here IQUIView+Hierarchy.m to work with UISearchBar.
-(BOOL)isSearchBarTextField
{
return NO;
}

- 2,385
- 3
- 32
- 44
-
1What is the reasoning behind explicitly disabling UISearchBar please Mohd? I'd rather not modify the library code directly if you had good reason to exclude search bar in the first place. – James Webster Jul 22 '16 at 08:21
-
1Library only disable toolbar, because UISearchBar should be dismiss using keyboard Search button. – Mohd Iftekhar Qurashi Jul 22 '16 at 19:02
-
@MohdIftekharQurashi how to do this with Swift 3.0 – ibnetariq Dec 20 '16 at 06:57
I made it work going to IQUIView+Hierarchy.swift
and commenting the searchBar()
part (as somebody else also pointed out):
if _IQcanBecomeFirstResponder == true {
_IQcanBecomeFirstResponder = isUserInteractionEnabled == true &&
isHidden == false && alpha != 0.0 &&
isAlertViewTextField() == false &&
// searchBar() == nil
}
Be aware that it is not recommended to modify pods directly (a major problem will be that at the next pod install
your changes will be wiped).
One solution (that I also use) is to fork the project, commit your changes and modify the podfile
to download IQKeyboardManager
from you repo.

- 3,417
- 1
- 32
- 39
-
very good approach to use your own repo! Brilliant idea! upvote I have experience with manual modification of dependencies, this is a source of nightmare for future changes, especially if someone else will work on your code. – Alex M.M. Sep 16 '19 at 13:52
In the file "IQUIView+Hierarchy.m", change this method:
-(BOOL)_IQcanBecomeFirstResponder
Change the line:
BOOL _IQcanBecomeFirstResponder = ([self canBecomeFirstResponder] && [self isUserInteractionEnabled] && ![self isHidden] && [self alpha]!=0.0 && ![self isAlertViewTextField] && ![self isSearchBarTextField]);
To:
BOOL _IQcanBecomeFirstResponder = ([self canBecomeFirstResponder] && [self isUserInteractionEnabled] && ![self isHidden] && [self alpha]!=0.0 && ![self isAlertViewTextField]);
You just have to delete ![self isSearchBarTextField]
from the condition.

- 3,751
- 7
- 53
- 76

- 19
- 1
I have the same issue using IQKeyboardManagerSwift with a UISearchController.
Apparently, an issue is pending on this on the official GitHub tagged as "Need Investgation". The potential solutions mentioened are :
This won't happen if:
- automaticallyAdjustsScrollViewInsets = false OR
- Use UITableViewController OR
- searchController.hidesNavigationBarDuringPresentation = false OR
- Disable IQKeyboardManager
For me,
searchController.hidesNavigationBarDuringPresentation = false
Did the job !
Hope this helps ;)

- 111
- 1
- 6