我有UITableview控制器,在标题中有搜索栏.当我向上滚动表格视图并且它反弹时.但搜索栏隐藏了.当我向下滚动然后显示的搜索栏.任何人都可以告诉我如何再次显示搜索栏?
我尝试了以下代码,但它无法顺利运行:
- (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];
}
}
这是错误的观点,滚动后:
最佳答案 如何禁用动画关闭并放置这样的自定义动画:
还可以确保使用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){
}
];
}
}