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 8163999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:12:17+00:00 2026-06-06T19:12:17+00:00

I want to add a accessoryView on a keyboard called from a UISearchBar. Since

  • 0

I want to add a accessoryView on a keyboard called from a UISearchBar. Since UISearchBar does not implement this property, I’ve just created a toolBar. Following Apple’s documentation on the matter, I’ve decided to use notification center not only to know when the keyboard is called but also to know the size of the keyboard, which changes depending on the orientation.

I’ve followed the example on the documentation and, on the keyboardWasShown method, I call an animation which will show the toolBar on top of the keyboard. Something like this:

-(void)keyboardWasShown:(NSNotification*)aNotification {

    NSDictionary *info=[aNotification userInfo];
    CGSize keyboardSize=[[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

     NSLog(@"width: %.1f; height: %.1f", keyboardSize.width, keyboardSize.height );

    [self showAccessoryView:keyboardSize.height];
}

and, on the animation I set the frame of the toolbar like this:

 self.auxiliaryKeyboardBar.frame=CGRectMake(0, self.view.frame.size.height-(44+kbh), self.view.frame.size.width, 44);

where 44 is the static height of the toolbar and the kbh is the keyboard.size.heigth passed from the method above.

The problem I’m observing is that the keyboard Size given by the userInfo Dictionary is always refered to the portrait orientation. So, the NSLog on portrait orientation is:

width: 320.0; heigth: 216.0, which is ok

but when I change the orientation to landscape and I call the keyboard, the NSLog is as follows:

width: 162.0; heigth: 480.0, which puts the toolbar out of scope.

so, I ended up adding a conditional before calling the animation, such as this:

if ([self deviceIsPortrait]==YES) {
        [self showAccessoryView:keyboardSize.height];
    }else if ([self deviceIsPortrait]==NO) {
        [self showAccessoryView:keyboardSize.width];
    }

I am now wondering whether or not I’m doing something wrong, because I’m following Apple’s example precisely to avoid dependence on the keyboard height (as a float) and I ended up having to add a orientation conditional anyway.

What’s going on here?

  • 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-06-06T19:12:19+00:00Added an answer on June 6, 2026 at 7:12 pm

    I think what you’re missing is this:

    CGRect keyboardFrameConverted = [mainSubviewOfWindow convertRect:keyboardFrame fromView:window];
    

    That’s a bit out of context, so here is the full implementation:

    - (void) keyboardDidShow:(NSNotification*)notification {
        CGRect keyboardFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
        NSLog(@"keyboard frame raw %@", NSStringFromCGRect(keyboardFrame));
    
        UIWindow *window = [[[UIApplication sharedApplication] windows]objectAtIndex:0];
        UIView *mainSubviewOfWindow = window.rootViewController.view;
        CGRect keyboardFrameConverted = [mainSubviewOfWindow convertRect:keyboardFrame fromView:window];
        NSLog(@"keyboard frame converted %@", NSStringFromCGRect(keyboardFrameConverted));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want add my custom sidebar next right column all page. Please check this
I have numbers in javascript from 01(int) to 09(int) and I want add 1(int)
I want to add a tab to a certain tab bar from inside the
I want add a UIToolbar to the keyboard for my UITextField . Here is
What should I do, if I want add routing rules from database. Should I
I want add user in ActiveDirectory. I use this code private SPUser CreateUser(string strLoginName,
I want add days to an NSDate . The approach below is not working.
I've created new content type. And I want add new custom non-standard field. The
I want add some methods. And this directive can't help me. var viewModel =
I want add new user from another script and I need create password for

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.