The table title bar looks like a search bar

How I would like the title view of the table view to freeze and not to be limited, even if the size of the overall contents of the table does not exceed the boundaries. As an example in Mail.app, even in non-message views, you can still scroll the search bar in and out of view (without the scroll bar that I have to add). How can I get this function without using the search display controller / search bar.

+3
source share
2 answers

Try setting the properties UIScrollView:

@property(nonatomic) CGPoint contentOffset
@property(nonatomic) BOOL alwaysBounceVertical

contentOffset height searchBar alwaysBounceVertical YES.

!

+2

, , UITableView, tableHeaderView UISearchBar. , . , , UISearchBar. , , , :

@interface HidingTableViewHeader : UISearchBar

- (id)initWithHeader:(UIView *)header;

@end

@implementation HidingTableViewHeader

- (id)initWithHeader:(UIView *)header
{
    // We don't really care about the search bar initialization
    self = [super init];
    if (self) {
        // Remove all the sub-views that make up the search bar UI
        [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        // Override UISearchBar fixed size
        self.size = header.size;
        // Match the tableHeaderView behavior: auto-resize horizontally
        header.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        // Make the header the only sub-view
        [self addSubview:header];
    }
    return self;
}

@end

:

self.tableView.tableHeaderView = [[HidingTableViewHeader alloc] initWithHeader:someRegularView];
0

Source: https://habr.com/ru/post/1752637/


All Articles