Using storyboard, I have placed an imageView as my tableView's headerView inside a ViewController.
This is how my storyboard is set up:

Depending on what data the user is viewing, the viewController will either show or hide the headerView. My question is, that when the headerView is visible and the user drags down on the tableView, how can I have the imageView stick to both the navigationBar and the tableView as it resizes to cover the space in between?
This is what it currently does:

But this is what I'm going for:

Any help would be greatly appreciated. I've looked at parallax libraries, but none support sectionTitles, and I'm not necessarily going for the parallax effect either. When the user scrolls up, I want it to bounce back to the regularView and not hide the headerView. Thanks!
UPDATE:
I have followed the advice posted by Dany below and have done the following:
-(void)scrollViewDidScroll:(UIScrollView*)scrollView { CGRect initialFrame = CGRectMake(0, 0, 320, 160); if (scrollView.contentOffset.y < 0) { initialFrame.size.height =! scrollView.contentOffset.y; childHeaderView.frame = initialFrame; } }childHeaderView is an imageView and for some reason when I drag down, the image moves up (like half of it behind the navBar) and doesn't return. Any advice would be greatly appreciated!! Thanks!
I recently posted a blog post about accomplishing this using constraints which might help, turns out it was quite straight forward.
Here is the link: Creating parallax effect on UIScrollView using constraints
First of all you should remove the UIImageView from the header and add it as a simple UIImageView on top of the UITableView then since UITableViewDelegate protocol conforms to UIScrollViewDelegate protocol you can implement the scrollViewDidScroll: method to check when the tableView is scrolling down and has a bouncing effect. something like this:
-(void)someInitMethod { initialFrame = yourHeaderView.frame; } -(void)scrollViewDidScroll:(UIScrollView*)scrollView { if(scrollView.contentOffset.y < 0) { initialFrame.size.height -= scrollView.contentOffset.y; yourHeaderView.frame = initialFrame; } } Also make sure you set the proper contentMode for your UIImageView. Also I think this implementation will create a bouncing effect but I'm not sure because I can't test it right now but I think this is a good start point for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With