Showing HUD when keyboard resigns as first responder makes it jump #125

pepejeria opened this Issue Dec 12, 2012 · 17 comments


None yet

The HUD will jump/moved down when showing it when a keyboard is visible and resigns as first responder.


pragma mark - UISearchBarDelegate

  • (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
    [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeGradient];
    [searchBar resignFirstResponder];

The HUD will first appear at the top of the screen and move down with the keyboard.

Older versions of of SVProgressHUD did not have this issue since it provided a method where the posY could be defined:
[SVProgressHUD showInView:self.view status:nil networkIndicator:YES posY:-1 maskType:SVProgressHUDMaskTypeClear];


samvermette commented Jan 8, 2013

The posY argument has long been gone. The HUD now always gets positioned according to the screen size and keyboard visibility.

Unfortunately I do not have a fix for you as you're the first to request this. Just to be sure, the HUD's position from top to bottom is animated right?

Yes, it animates down to the new position.


samvermette commented Jan 9, 2013

What if you try resigning first responder before showing the HUD? Same result?

I'm seeing this too. I had the resign first responder before showing the HUD.

Is there a way to make it appear over the keyboard? That would make it less awkward.


samvermette commented Jan 11, 2013

Good call, but that means I need to stick to UIWindow (there's been a lot of pressure for me to move to UIView instead). Will think about this.

borut-t commented Feb 18, 2013

@pepejeria: I had the same issue. I solved it using blocks:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_current_queue(), ^{});

Most animations duration in iOS are defaulted to 0.3 second. Show/hide keyboard duration is also 0.3 second. So all you need to do is to show hud after that period.

Here is the example code:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar 
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
        [SVProgressHUD showWithStatus:@"Searching..." maskType:SVProgressHUDMaskTypeBlack];

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            //do search
            dispatch_async(dispatch_get_main_queue(), ^{
                //search finished - do smth with search results and hide hud
                [SVProgressHUD dismiss];

getaaron commented Feb 26, 2013

You can get the actual keyboard animation duration from the notification's userInfo dictionary with UIKeyboardAnimationDurationUserInfoKey.

- (NSTimeInterval)keyboardAnimationDurationForNotification:(NSNotification*)notification
    NSDictionary* info = [notification userInfo];
    NSValue* value = [info objectForKey:UIKeyboardAnimationDurationUserInfoKey];
    NSTimeInterval duration = 0;
    [value getValue:&duration];
    return duration;

Sample code from this Stack Overflow answer.

(You can also get the curve available with the key UIKeyboardAnimationCurveUserInfoKey returned to you as an NSNumber object containing a UIViewAnimationCurve constant.)

Is there any updated thinking on the best resolution for this issue? dispatch_get_current_queue() was deprecated in iOS 6.0.

borut-t commented Jan 21, 2014

@markdorison try this:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    [SVProgressHUD showWithStatus:@"Searching..." maskType:SVProgressHUDMaskTypeBlack];

honkmaster commented Dec 4, 2014

Is the issue still present?


samvermette commented Dec 8, 2014

Haven't come across it in a long while. Closing for now, reopen if you can reproduce this.

samvermette closed this Dec 8, 2014


honkmaster commented Dec 8, 2014

Shouldn't happen again, because we have a new keyboard method, which fixes the bug (at east for me).

@samvermette I'm still able to reproduce this with iOS 8.3

In my searchBarSearchButtonClicked: method I call resignFirstResponder and then display SVProgressHUD through GCD using @borut-t's code, but I still get the slide down animation.

itzAsim commented Mar 3, 2016

Issue still occurring with iOS9 too.

+1 for occuring in iOS 9 as of May 2016.

extension SVProgressHUD {

    func visibleKeyboardHeight() -> CGFloat {

        return 0.0

+1 for occuring in iOS 9 as of August 2016.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment