iphone - 以与邮件应用程序相同的方式显示/隐藏 UITableView header (UITextField)

标签 iphone cocoa-touch

我想以与标准邮件应用程序使用 UISearchBar 完全相同的方式显示和隐藏 UITableView header (UITextField),但无法弄清楚如何实现该行为。

与我相关的行为如下:

  • 首次显示时,标题(搜索栏)会隐藏。
  • 当用户向下滚动时,会显示标题。
  • 即使表格内容(行)没有填满整个表格 View ,标题也可以滚动回视线之外(非常重要)。
  • 返回同一 View 时, header 的位置与原来的位置完全相同(完全在 View 中、完全在 View 之外或介于两者之间)。

关键是即使表格内容(行)没有填满整个 View ,也能够将标题滚动回视线之外。

我尝试设置 contentOffset,虽然我可以通过这样做隐藏第一个 View 的标题,但当表格内容(行)没有填满整个表格 View 时,标题无法滚动回到视线之外。这个方法。

有人可以在这里提供任何建议吗?

最佳答案

你有没有得到你想要的东西?我不久前在一些代码中就有这个,它可以满足您的要求。下拉 40 像素时在标题中显示搜索栏。当表格向上滚动 40 像素时,隐藏回导航栏下方。

搜索是我在搜索栏处于事件状态时设置的 iVar 标志。

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    CGFloat amountOfDrag = scrollView.contentOffset.y;
    UIEdgeInsets edgeAtEntry = self.tableView.contentInset;
    UIEdgeInsets edgeSetNew;
    CGFloat underlay = self.topLayoutGuide.length;
    CGFloat searchBarViewHeight = 44.0f;
    BOOL needsReset = NO;
    if (amountOfDrag <= -40 && edgeAtEntry.top == underlay - searchBarViewHeight) {
        needsReset = YES;
        edgeSetNew = UIEdgeInsetsMake(0.0f + underlay, 0.0f, self.bottomLayoutGuide.length, 0.0f);
    } else if (amountOfDrag >= 40 && edgeAtEntry.top != underlay - searchBarViewHeight) {
        needsReset = YES;
        edgeSetNew = UIEdgeInsetsMake(-searchBarViewHeight + underlay, 0.0f, self.bottomLayoutGuide.length, 0.0f); //hides searchbar under navbar
    }

    if (needsReset && !searching) {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.2];
        scrollView.contentInset = edgeSetNew;
        [UIView commitAnimations];
    }
}

关于iphone - 以与邮件应用程序相同的方式显示/隐藏 UITableView header (UITextField),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6208890/

相关文章:

ios - 在 iOS 后台模式下继续从 html5 播放器播放音频

iphone如何指定Class数据类型必须采用某种协议(protocol)

ios - 为什么从 Activity Monitor 和 Instruments 上看到的内存消耗如此不同。

iphone - 后退按钮似乎已禁用 iOS

iphone - 尝试在没有 NIB 的情况下在 View 中显示 UILabel

iphone - bool 参数在 animateWithDuration :animations:completion: 中究竟做了什么

iphone - 检测在 pagingEnabled UIScrollView 中显示的是哪个 UIView

iphone - setAnimationTransition 显然被忽略了

ios - iPhone (iOS 7) 应用程序图标异常行为

ios - 字典响应错误