ios - 搜索栏不接收触摸

标签 ios objective-c uitableview searchbar

the search bar does not receive touches when scrolled but does receive when it is on the original contentOffSet我实现了一个搜索栏,它“粘”在 tableView 上。现在,在 tableView 开始滚动后,searchBar 不会接收触摸并成为第一个响应者,而是其后面的单元格接收触摸并导航到下一个 View 。我该怎么做才能让 searchBar 接收触摸?

保持静态的代码:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView {

    UISearchBar *searchBar = self.search;
    [[self.tableView.tableHeaderView superview] bringSubviewToFront:self.tableView.tableHeaderView];
    CGRect searchBarFrame = searchBar.frame;
    if (self.inSearchMode)
    {

        searchBarFrame.origin.y = 0;
    }
    else
    {

        searchBarFrame.origin.y = MAX(0, scrollView.contentOffset.y + scrollView.contentInset.top);
    }

    self.search.frame = searchBarFrame;
}

最佳答案

如果您考虑一下,当您滚动时,表格标题框将在表格边界之外。 尝试将其作为 subview 直接添加到 tableView 并设置其相对于 tableView 边界的框架以保持其粘性。

关于ios - 搜索栏不接收触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31825219/

相关文章:

iphone - 为什么我的 UILabel 没有使用 NSUserDefaults 保存/加载?

uitableview - fatal error : unexpectedly found nil while unwrapping an Optional value on table view cell

ios - 通过应用发送 facebook 请求

iphone - Objective-C 实现文件中方法名后的分号

iOS 应该模型对象能够使用 NSURLSession 访问网络

iPhone Web 服务和表格 View

iphone - UIView 应该有多个 UITableViews 作为 subview

ios - 在方法运行之前使用可达性检查连接

ios - 在 iOS 教程中, "Property toDoItems not found on object type of XYZToDoListViewController"

ios - Objective-C:像 2014-02-02T20:55:31.555Z 这样的日期的日期格式是什么