表格视图标题隐藏像搜索栏

时间:2010-07-01 13:42:41

标签: ios objective-c uitableview uiview uikit

即使表的总内容大小不大于边界,我如何让表视图的标题视图滚入和跳出边界。作为Mail.app中的一个示例,即使在没有消息的视图中,您仍然可以在视图中滚动搜索栏(我不应该添加滚动条)。如何在不使用搜索显示控制器/搜索栏的情况下获得此功能。

2 个答案:

答案 0 :(得分:2)

尝试设置UIScrollView的属性:

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

contentOffset设置为height的{​​{1}}和searchBaralwaysBounceVertical

这应该可以做到!

答案 1 :(得分:0)

UITableView的{​​{1}}设置为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's 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];
相关问题