Katedral Pillon
Katedral Pillon

Reputation: 14864

how to get iqkeyboardmanager to include UISearchBar

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?

Upvotes: 2

Views: 4579

Answers (4)

Teodor Ciuraru
Teodor Ciuraru

Reputation: 3477

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.

Upvotes: 2

Cyprille CHAUVRY
Cyprille CHAUVRY

Reputation: 111

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 ;)

Upvotes: 1

Hamdi Bouasker
Hamdi Bouasker

Reputation: 19

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.

Upvotes: 1

Mohd Iftekhar Qurashi
Mohd Iftekhar Qurashi

Reputation: 2405

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;
}

Upvotes: 6

Related Questions