我有UITableview Controller,它在标题中有搜索栏。当我向上滚动表格视图并且它反弹时。但搜索栏隐藏了。当我向下滚动然后显示的搜索栏。任何人都可以告诉我如何再次显示搜索栏?
我尝试了以下代码,但它无法顺利运行:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat sectionHeaderHeight = 40;//Change as per your table header hight
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
//scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
CGPoint newOffset = CGPointMake(0, -[self.tableView contentInset].top);
[self.tableView setContentOffset:newOffset animated:YES];
}
}
这是错误的观点,滚动后:
答案 0 :(得分:1)
如何禁用动画关闭并放置这样的自定义动画:
也确保使用MAcro具有相同的sectionHeader高度。我仍然怀疑你的评论是35或25。
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat sectionHeaderHeight = 40;//Change as per your table header hight
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
[UIView animateWithDuration: 1.0
animations: ^{
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
}completion: ^(BOOL finished){
}
];
} else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
CGPoint newOffset = CGPointMake(0, -[self.tableView contentInset].top);
[UIView animateWithDuration: 1.0
animations: ^{
[self.tableView setContentOffset:newOffset animated:NO];
}completion: ^(BOOL finished){
}
];
}
}
答案 1 :(得分:0)
试试这段代码
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat sectionHeaderHeight = 40;
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
}
else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}
但问题是,你的tableview标题不是40,它是35或25,这意味着你的tableview无法为插图设置正确的数字,请尝试更改40以更正标题高度。