0

Please help me to make the UICollectionview header transparent while we scroll the collection view up. I have used UICollectionReusableView and set it background as clear color, but no use. WHILE MOVING UP THE HEADER ( SHOWN IN BLACK COLOR) SHOULD BECOME TRANSPARENT.... THAT IS THE ORANGE BACKGROUND SHOULD BE SLIGHTLY VISIBLE....

enter image description here

Fionashoff
  • 752
  • 9
  • 30
  • Could you, please, be more specific? In what moment do you set background of UICollectionReusableView? How do you access it? The best would be, if you can post some code – Sergii Martynenko Jr Jul 28 '15 at 09:56
  • And what do you mean, "UICollectionview header". It's not quite clear, 'cause UICollectionView doesn't have `header` property (like UITableView has) – Sergii Martynenko Jr Jul 28 '15 at 10:14

1 Answers1

0

Not enough info, but I'll try to answer

First, you should keep pointer to your header view constantly

@property UICollectionReusableView *collectionHeaderView;

Create it once in viewDidLoad and than use it as a header view (whatever that means) in your collection view.

Next, to change collor on dragging up you'll need delegate method. UICollectionViewDelegate conforms to UIScrollViewDelegate, so you can use its method

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{ 
     CGPoint translation = [scrollView.panGestureRecognizer translationInView:scrollView.superview];

     if(translation.y > 0)
     {
        //dragging down
        collectionHeaderView.backgroundColor = <#Whatever you need#>;
     } else
     {
         // dragging up
         collectionHeaderView.backgroundColor = [UIColor clearColor];
     }
 }

Special thanks to @mvielbut for answer

Update

According to comments to mvielbut's answer, this method is not always reliable, so you can use another approach (you'll need to check offset.y instead).

Community
  • 1
  • 1
Sergii Martynenko Jr
  • 1,377
  • 1
  • 8
  • 18