Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 表视图标题隐藏类似搜索栏_Ios_Objective C_Uitableview_Uiview_Uikit - Fatal编程技术网

Ios 表视图标题隐藏类似搜索栏

Ios 表视图标题隐藏类似搜索栏,ios,objective-c,uitableview,uiview,uikit,Ios,Objective C,Uitableview,Uiview,Uikit,即使在表的总体内容大小不大于边界时,我如何让表视图的标题视图在边界内外滚动。例如,在Mail.app中,即使在没有消息的视图中,您仍然可以在视图中滚动搜索栏(没有我应该添加的滚动栏)。如何在不使用搜索显示控制器/搜索栏的情况下获得此功能。请尝试设置UIScrollView的属性: @property(nonatomic) CGPoint contentOffset @property(nonatomic) BOOL alwaysBounceVertical 将contentOffset设置为搜

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

请尝试设置
UIScrollView
的属性:

@property(nonatomic) CGPoint contentOffset
@property(nonatomic) BOOL alwaysBounceVertical
contentOffset
设置为
搜索栏的
高度
alwaysBounceVertical
设置为
YES


那就应该成功了

当其
tableHeaderView
设置为
UISearchBar
的实例时,您看到的是
UITableView
的一种特殊行为。我相信这种行为是硬编码的。因此,要将其用于您自己的视图,您需要扩展
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];

这不起作用,因为偏移量只允许您在contentSize大于边界时向上滚动视图。因此,在空表视图中,您无法再向上滚动它。不知何故,在IB中添加一个搜索栏会覆盖这一点,在mail.app中的任何空邮箱中都可以看到这一点。我已将答案编辑为包含alwaysBounceVertical。使用这两个属性可以使它按照您在我当前正在处理的项目中所描述的那样工作。让我知道!