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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:00:37+00:00 2026-06-18T04:00:37+00:00

When I add some hidden header view, like search bar, to the table view,

  • 0

When I add some hidden header view, like search bar, to the table view, it scrolls automatically to content’s top or table cell’s top, when I set the offset of the scroll to the middle of a search bar. (I used below code)

// in viewDidLoad section
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]
[self.tableView setTableHeaderView:searchBar]

// in viewWillAppear: section
[self.tableView setContentOffset:CGPointMake(0, 44)];

For example, if I scroll up a little amount when the search bar is hidden, it automatically scrolls to display the entire search bar.
And if I scroll down a little when the search bar is displayed, it automatically scrolls to make the search bar hidden.

I used below code to implement this feature to my collection view’s header, but that wasn’t exactly the same as the table view’s feature.

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    CGFloat offset = scrollView.contentOffset.y;
    if (offset > 22 && offset < 44) {
        [scrollView setContentOffset:CGPointMake(0, 44) animated:YES];
    } else if (offset > 44) {
        return;
    } else {
        [scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
    }
}

I think it is very hard to mimic above feature exactly, because the judgment of displaying the entire search bar or hiding the search bar is very subtle.

So my question is, “Is there any pre-implemented method in iOS SDK, or in UICollectionViewController?”.

I googled for many hours but I couldn’t found the answer.

  • 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-18T04:00:39+00:00Added an answer on June 18, 2026 at 4:00 am

    I couldn’t find the pre-implemented way to implement that feature, but the below way seems to make things similar to that of table view’s.

    First, add CGFloat type ivar originScrollOffset.

    Then, I used the below code to implement scroll view delegate.

    - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
    {
        originScrollOffset = scrollView.contentOffset.y;
    }
    
    - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
    {
        CGFloat endScrollOffset = scrollView.contentOffset.y;
        NSLog(@"%f %f", originScrollOffset, endScrollOffset);
        if (endScrollOffset <= 44 && endScrollOffset >= 0) {
            if (originScrollOffset >= 44) {
                if (originScrollOffset - endScrollOffset > 10) {
                    originScrollOffset = 0;
                    [self.collectionView setContentOffset:CGPointMake(0, 0) animated:YES];
                } else {
                    originScrollOffset = 44;
                    [self.collectionView setContentOffset:CGPointMake(0, 44) animated:YES];
                }
            } else {
                if (endScrollOffset - originScrollOffset > 10) {
                    originScrollOffset = 44;
                    [self.collectionView setContentOffset:CGPointMake(0, 44) animated:YES];
                } else {
                    originScrollOffset = 0;
                    [self.collectionView setContentOffset:CGPointMake(0, 0) animated:YES];
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just want to add some extra text on top of input posted from
I need to add some total rows to a table. The code I am
I want to add some hidden field in Flex and send to the server
I would like to add some JavaScript to do the following. I would have
I'm trying to add some UI elements like UIProgressView , UILabel , UIButton and
I'd like to add some values under the jquery progress like My current code
I want to add some columns to a table (Swing JTable). Some of them
When I try to add some entries into the join table of two classes,
I use this wonderful script to make my table sortable and add some filters
I have an html table that I am trying to add some animation to

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.