How to make a view gone on scrolling in ios


I have a view which i want to scroll up on my tableview scrolling.

<a href="https://i.stack.imgur.com/eXVDd.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/eXVDd.png" data-original="https://i.stack.imgur.com/eXVDd.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

this is the view which will scroll up whenever i am scrolling my tableview. but this is what happens when i do that:

<a href="https://i.stack.imgur.com/8IQjH.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/8IQjH.png" data-original="https://i.stack.imgur.com/8IQjH.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

As u can see there is a black space in between my targeted view and the tableview.

on my <strong>scrollViewDidScroll</strong> 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 }

<strong>scrolloffset</strong> 0 indicates top and the <strong>heightConstraint</strong> is the height constraint of <strong>parentOfPhotoview</strong> which is the desired view!!

<strong>What is i am missing??</strong>


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 0; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 0; }

Try above line of code. May be your problem will be solved.


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.

However, I would suggest using AutoLayout.

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

And make sure you set the height of header in section to be the same as the parentPhotoView


  • How to send link in colmn to a external PHP function for viewing of Zip contents in jqgrid?
  • UITableview reusable cell issue swift
  • sql server pivot : group by with dynamic columns
  • PyQt QAbstractTableModel checkbox not checkable
  • jqgrid - error when moving from 1 page to another
  • Parallax background tiled imperfectly
  • Filter NSMutableDictionary data in UITableView
  • DuplicateKeyException in LINQ, but I've set auto increment and auto sync
  • Get all data in html table into array
  • Why use keys filter instead of columns.slice()?
  • ProgressBar Paint Method?
  • How to show a badges count of ToolBarItem Icon in Xamarin Forms
  • 'Enemy' was not declared in this scope?
  • How can a flex item keep the same dimensions when it is forced to a new row?
  • Load 24 bit TGA
  • how to resolve OAuthException: (#100)
  • Position Fixed in Chrome
  • jParallax trouble
  • How to get a table cell value using jQuery
  • Updating one element of a bound Observable collection
  • How to remove all of a jQuery UI dialog when it is closed
  • Parenthesis() and SQL Query Performance
  • Responsive Form on top of Responsive Image? - Bootstrap
  • jQuery - resize an elements height to match window without refreshing, on window resize
  • Flex items with same property values are rendering in different sizes
  • chrome video src change not working
  • For loop with if condition on multiple R functions
  • WPF Template Binding in ToggleButton UserControl
  • blade.php method outputting it's result to the form
  • Floated image with variable width and heading with background image
  • as3-flash: any way to access all the instances placed in different frames from document class?
  • Can't delete or rename original file after resizing
  • D3 get axis values on zoom event
  • wxPython: displaying multiple widgets in same frame
  • OpenGL 3.3 on Mac OSX El Capitan with LWJGL
  • R - Combining Columns to String Based on Logical Match
  • How to set/get protobuf's extension field in Go?
  • How to show dropdown in excel using jrxml (jasper api)?
  • embed rChart in Markdown
  • Unable to use reactive element in my shiny app