如何使视图继续在 ios 中滚动 [英] How to make a view gone on scrolling in ios
问题描述
我有一个视图,我想在我的 tableview 滚动中向上滚动.
I have a view which i want to scroll up on my tableview scrolling.
这是每当我滚动 tableview 时都会向上滚动的视图.但当我这样做时会发生这种情况:
this is the view which will scroll up whenever i am scrolling my tableview. but this is what happens when i do that:
如您所见,我的目标视图和 tableview 之间有一个黑色空间.
As u can see there is a black space in between my targeted view and the tableview.
在我的 scrollViewDidScroll 上,我这样做了:
on my scrollViewDidScroll i did this:
CGPoint offset = scrollView.contentOffset;
self.counter = 0;
CGRect bounds = scrollView.bounds;
CGSize size = scrollView.contentSize;
UIEdgeInsets inset = scrollView.contentInset;
float y = offset.y + bounds.size.height - inset.bottom;
float h = size.height;
float reload_distance = 10;
float scrollViewHeight = scrollView.frame.size.height;
float scrollContentSizeHeight = scrollView.contentSize.height;
float scrollOffset = scrollView.contentOffset.y;
self.tableData.contentInset = UIEdgeInsetsZero;
if (scrollOffset == 0)
{
[self.topView removeFromSuperview];
[[self navigationController] setNavigationBarHidden:NO animated:YES];
[self changeHeight:48];
self.parentOfPhotoview.frame =CGRectMake(0, 0, self.parentOfPhotoview.frame.size.width, self.heightConstraint.constant);
}
else if(scrollOffset>2)
{
//[[self navigationController] setNavigationBarHidden:YES animated:YES];
//[self.view addSubview:_topView];
if(self.heightConstraint.constant<2)
{
[self changeHeight:0];
}
else
{
[self changeHeight:48-(scrollView.contentOffset.y)];
self.parentOfPhotoview.frame = CGRectMake(0, -scrollView.contentOffset.y, self.parentOfPhotoview.frame.size.width, self.heightConstraint.constant);
self.parentOfPhotoview.backgroundColor = [UIColor whiteColor];
NSLog(@"%f",self.heightConstraint.constant);
}
}
else if (scrollOffset + scrollViewHeight == scrollContentSizeHeight)
{
// then we are at the end
}
scrolloffset 0 表示顶部,heightConstraint 是parentOfPhotoview 的高度约束,这是所需的视图!
scrolloffset 0 indicates top and the heightConstraint is the height constraint of parentOfPhotoview which is the desired view!!
我错过了什么?
推荐答案
您应该将表格 contentInset 设置为与导航栏具有相同高度的顶部.黑色是根本没有视图的时候.这样你就不必担心改变 tableView 的高度等.
You should set your table contentInset with the Top having the same height as the navigationBar. The black is when there is no views at all. This way you do not need to worry about changing height of the tableView etc.
不过,我建议使用 AutoLayout.
However, I would suggest using AutoLayout.
另外,如果您想让 parentPhotoView 浮动在表格顶部.您在部分标题的视图中设置.
Also if you want to have parentPhotoView to be floating on the top of the table. You set that in the view for header in section.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
并确保将 section 中 header 的高度设置为与 parentPhotoView 相同
And make sure you set the height of header in section to be the same as the parentPhotoView
这篇关于如何使视图继续在 ios 中滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!