Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7191749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:47:44+00:00 2026-05-28T19:47:44+00:00

I have a view-based application, and in one of the subviews there is a

  • 0

I have a view-based application, and in one of the subviews there is a UIScrollView. I have written handlers to adjust the size of the scroll view when the keyboard appears and disappears. I would like the keyboard to be dismissed when the user leaves the view, so I call [currentField resignFirstResponder] in viewWillDisappear. This dismisses the keyboard, but does not call the handler to resize the scroll view (when I call the same code in other places, it does). Any suggestions?

EDIT: These are the handlers that I use:

-(void) keyboardWasShown:(NSNotification*) notification
{
    if(keyboardShown)
        return;

    NSDictionary* info=[notification userInfo];
    NSValue* value=[info objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGSize keyboardSize=[value CGRectValue].size;
    CGRect viewFrame=[scrollView frame];
    viewFrame.size.height-=keyboardSize.height;
    scrollView.frame=viewFrame;

    keyboardShown=YES;
}

-(void) keyboardWasHidden:(NSNotification*) notification
{
    NSDictionary* info=[notification userInfo];
    NSValue* value=[info objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGSize keyboardSize=[value CGRectValue].size;
    CGRect viewFrame=[scrollView frame];
    viewFrame.size.height+=keyboardSize.height;
    scrollView.frame=viewFrame;

    keyboardShown=NO;
}

When I call [currentField resignFirstResponder] anywhere else, it calls the handler without problems.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:47:46+00:00Added an answer on May 28, 2026 at 7:47 pm

    So you were being removed as observer before UIKeyboardDidHideNotification was posted, glad I could help. But observing the UIKeyboardWillHideNotification and UIKeyboardWillShowNotification is probably enough for your reaction to the keyboard. The keyboard notifications have a user info key UIKeyboardAnimationDurationUserInfoKey which you can use to animate your frame adjustments with the keyboard animations. This avoids the ‘clunk’ feeling your views will have if you don’t animate them to new positions. Here is a quick example of what you can do:

    -(void)keyboardWillNotificationTarget:(NSNotification *)note{
            // Find current keyboard origin Y 
        NSValue *keyboardCurrentFrameValue = [note.userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey];
        CGFloat currentOriginY = keyboardCurrentFrameValue.CGRectValue.origin.y;
            // Find keyboard Y that will be
        NSValue *keyboardNewFrameValue = [note.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
        CGFloat newOriginY = keyboardNewFrameValue.CGRectValue.origin.y;
            // Calculate new frame for scrollView
        CGFloat heightChangeForScrollView = newOriginY - currentOriginY;
        CGRect svFrame = scrollView.frame;
        svFrame.size.height += heightChangeForScrollView;
            // Find duration of animation
        NSNumber *animationDurationNumber = [note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
        CGFloat animationDuration = animationDurationNumber.floatValue;
            // Animate scrollView with keyboard
        [UIView animateWithDuration:animationDuration animations:^{
            scrollView.frame = svFrame;
        }];
    }
    

    Now you simply add this method as the target for both notifications:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillNotificationTarget:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillNotificationTarget:) name:UIKeyboardWillHideNotification object:nil];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a web based application with only one view controller. i have some
I have created one navigation based application. In that first view show me the
I have an view-based application where the user can do a lot of customization
I have a UITabBar in the detail view of my navigation based application. I
I have just added a Core Plot view to my application based on a
I have a multiple view based application, the problem is that when I push
I have this problem, I've got a navigation-based application, and on the one of
I create an application base on view based Application project . so i have
I have a navigation based application and in the child view I have a
i have view based application, and i want to call a method in superview(parentview)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.