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

  • Home
  • SEARCH
  • 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 8370407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:54:16+00:00 2026-06-09T13:54:16+00:00

I have a UISearchBar inside of UIScrollView (well, to be precise an AQGridView). Now

  • 0

I have a UISearchBar inside of UIScrollView (well, to be precise an AQGridView). Now the searchBar shall be hidden initially (as you see in the Music app for instance). As UIScrollViews don’t have a header view, I placed it -40 points outside of the UIScrollView’s frame and also set the contentInset to 40 points.

searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.f, -40.f, 320.f, 40.f)];
gridView.contentInset = UIEdgeInsetsMake(0.f, 40.f, 0.f, 0.f);

Now from the look and general behavior that pretty much does exactly what I want. The search bar is hidden, but I can scroll up to reveal it.

Now here’s the thing:

When I touch on the searchBar to give it focus and enter some text everything works fine except when the searchBar is not entirely visible. In that case the UIScrollView tries to automatically scroll it to complete visibility. However, it scrolls in the wrong direction.

So when, say, 10 points on top of the search bar are hidden, the scroll view scrolls down instead of up.

This might be a little bit vague a question, but maybe someone can tell my mistake here… The only thread I could find here was this one: uitableview contentInset issue but that also didn’t seem to help my case.

  • 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-09T13:54:17+00:00Added an answer on June 9, 2026 at 1:54 pm

    I met alomost the same problem and CodaFi’s solution just cannot solve my problem.
    So I kind of doubting this solution as the correct answer.

    Here is the description of my situation and problem:
    I want to add the UINavigationBar into the ContentInset area and UIWebView in ContentSize area of UIScrollView so that UINavigationBar can go and disappear with the web content outside the top of screen when scrolling down. And also inside the UINavigationBar I added one UITextField and one UISearchBar (yes, just like the Safari). Following the part of setting code(in viewDidLoad: method):

    navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, -64, 320, 64);
    textfield = [[UITextField alloc] initWithFrame:CGRectMake(5, 23, 150, 30)];
    [navigationBar addSubview:textfield];
    searchbar = [[UISearchBar alloc] initWithFrame:CGRectMake(200, 23, 100, 30)];
    [navigationBar addSubview:searchbar];
    [self.webView.scrollView setContentInset:UIEdgeInsetsMake(64, 0, 0, 0)];
    [self.webView.scrollView setContentOffset:CGPointMake(0, -64) animated:NO];
    [self.webView.scrollView addSubview:navigationBar];
    

    The problem is that when I click the textfield or searchbar, the navigationbar(actually with the whole view) goes down in the screen: textfield by 41 points, and searchbar by 42 points(weird!). So it leaves a whole mysterious white space from 0 to 41(or 42) points on the upside of screen. And another weird thing is that it only happens once! After I scroll the screen by finger, it disappears and never shows up again the second time when I click the textfield or searchbar.
    I believe the essence of my problem is just like Dennis’s.

    After searching on the web for two days, Unfortunately, I could not find the perfect solution to fix the essence of this problem(actually I am not even quite sure about the essence of the problem…).

    But as I experimented and observed, my assumption would be that the 41 points that the textfield moved down could be because of the relative position it is set(-64 + 23 = -41) on the navigationbar. And when it is click by user, the system(iOS) checked its position(although I have already set the contentOffset by -64 in viewDidLoad:) and find it is not in the scope of the user and force the scrollview to scroll down until it shows up(41 points toward downside).
    I can not understand the behavior of scrollview if we(developer) set a content inset area and interact with it. There is really few document and referrence talking about it. I wish my assumption was wrong and someone could correct me in the future and help us find the truth.

    Last, although I could not find the “real” answer, actually I found a solution to this problem (like a remedy to cure the symptom). Here is the code:

    - (void) scrollViewDidScroll:(UIScrollView *)scrollView {
        if (scrollView.contentOffset.y < -64) {    // if it is beyond the contentInset area
            if (!scrollView.dragging && !scrollView.decelerating) {    // scrollView is operated by system
                [scrollView setContentOffset:CGPointMake(0, -64) animated:NO];  // freeze the screen at (0, -64) position
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UISearchBar which I am putting in UISearchDisplayController. Now, whenever I tap
I have a UISearchbar with delegate method - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { if(searchText.length>3){
Basically what I want to do in my app is have a UISearchBar which,
I have an app which uses a UISearchBar to dynamically search from an external
I have placed a UISearchBar in my UITableView.tableHeaderView. However it covers the searchBar by
I have the following UISearchbar code: - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { [UIApplication sharedApplication].networkActivityIndicatorVisible
I have a UISearchBar in my app, and I'm running the following code with
I have a UISearchBar in a titleView of Navigation bar, i did use [searchBar
I have the following code for my UISearchBar: UISearchBar * searchBar = [[UISearchBar alloc]
I have uisearchbar in a uiview which is already subview of a uiviewController, I

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.