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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:55:07+00:00 2026-06-11T11:55:07+00:00

Has anyone tried using a UISearchDisplayController with a UISearchBar that is a UIBarButtonItem in

  • 0

Has anyone tried using a UISearchDisplayController with a UISearchBar that is a UIBarButtonItem in a UIToolbar?

I would appreciate tips on how to do this successfully.

Currently whenever the search controller pops up it redraws the UISearchBar and I’m struggling to maintain a similar look to the UIToolbar

  • 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-11T11:55:08+00:00Added an answer on June 11, 2026 at 11:55 am

    Usually you don’t want to put a search bar inside a toolbar, however, it seems you want to do something similar to what I did.

    So here is how I did it, it may be called a hack, but it works like a charm 🙂

    First you have to set it up in interface builder like this:

    enter image description here

    Notice that the search is not a child of toolbar, instead it is above.

    The search bar should have “clear color” background and flexible left, right and width autoresizing masks.

    You put a 1-pixel label with black background below the toolbar, ie. [x=0, y=44, width=320 or frame width, height=1], also flexible left, right and width autoresizing masks.This is to hide the one visible pixel you get, after the search display controller shows the table view. Try it without it to understand what I mean.

    You setup any tool bar items and be sure to have outlets for them, since you will be needing those.

    and now for the code …

    when you start searching:

    - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
    {
        // animate the search bar to the left ie. x=0
        [UIView animateWithDuration:0.25f animations:^{
            CGRect frame = controller.searchBar.frame;
            frame.origin.x = 0;
            controller.searchBar.frame = frame;
        }];
        // remove all toolbar items
        [self.toolbar setItems:nil animated:YES];
    }
    

    when you end searching

    - (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller
    {
        // animate search bar back to its previous position and size
        // in my case it was x=55, y=1
        // and reduce its width by the amount moved, again 55px
        [UIView animateWithDuration:0.25f 
                              delay:0.0f
                            // the UIViewAnimationOptionLayoutSubviews is IMPORTANT,
                            // otherwise you get no animation
                            // but some kind of snap-back movement 
                            options:UIViewAnimationOptionLayoutSubviews 
                         animations:^{
                             CGRect frame = self.toolbar.frame;
                             frame.origin.y = 1;
                             frame.origin.x = 55;
                             frame.size.width -= 55;
                             controller.searchBar.frame = frame;
                         } 
                         completion:^(BOOL finished){
                             // when finished, insert any tool bar items you had
                             [self.toolbar setItems:[NSArray arrayWithObject:self.currentLocationButton] animated:YES];
                         }];
    }
    

    With this I get the following with a nice animation 🙂

    enter image description here

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone successfully tried minifying AND concatenating all the jqGrid locale files so that
Has anyone tried compiling SciPy 0.7.1 on Windows using numpy-1.3.0 that was built with
Has anyone else tried using SimpleModal in IE9? If so, have you experienced that
Has anyone successfully tried using Microphone.getEnhancedMicrophone() method in Adobe Flash CS5? I tried all
Has anyone of you tried using rotating proxies? How easy is this to implement?
Has anyone tried using the NHibernate Velocity L2 cache provider against the Azure AppFabric
Has Anyone tried using PDF in iPad Application, using CGPDf functions. I have used
Has anyone tried to back up a SharePoint web application using forms based authentication
Has anyone ever tried sending emails using 1&1 smtp host? I tried the following?
Has anyone tried taking a video from the camera and then using the video

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.