0

I have a UIScrollView that has a bunch of text in it. As the user scrolls up I create a little color-to-transparent view at the top so the text doesn't look like it just drops off.

I have the scrollView working fine, delegates set, etc.

Which all this works fine and dandy and I get this (which is what I want):

Before scrolling:

enter image description here

As I start to scroll down it grows like it's suppose to:

enter image description here

As I scroll up it shrinks like it's suppose to:

enter image description here


Problem: However! If I flick it up fast it seems that scrollViewDidScroll:(UIScrollView *)scrollView doesn't get called fast enough and the frame for the gradient never gets updated. Is there another scollView delegate method that I need to be checking? Or maybe I am going about handling the gradient all the wrong way.

enter image description here


Here is my scrollViewDidScroll:(UIScrollView *)scrollView method to handle updating the gradient frame:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

    //Only want our gradient to show if text is off screen
    if (scrollView.contentOffset.y >= 0) {

        //Dont want our gradient to be larger than 8 pixels tall
        if (scrollView.contentOffset.y <= 8) {

            //Grab our view that draws gradient frame
            CGRect frm = self.shadeView.frame;

            //Set it the size to be absolute value of our scrollView offset
            frm.size.height = abs(scrollView.contentOffset.y);

            //Set the frame
            self.shadeView.frame = frm;
        }
    }
    //If the scrollView is scrolled to the top we don't want to show our gradient so we set it's height to 0. 
    else {
        CGRect frm = self.shadeView.frame;
        frm.size.height = 0;
        self.shadeView.frame = frm;
    }
}
random
  • 8,568
  • 12
  • 50
  • 85
  • Is the text put on a UILabel or UITextView? How about change the background to the same with the scroll view? – sunkehappy Sep 27 '12 at 01:00
  • It's not clear from the screenshots you posted where/what the gradient effect is. It seems like maybe you could get around this issue by positioning the gradient above the scrollview in the view hierarchy, so you're not having to move it, but it's hard to tell from the screenshots exactly how it is supposed to be applied. – Rob Reuss Sep 27 '12 at 03:55
  • @RobReuss the gradient is drawn in the white block (view) in the screen shots. I just took out the gradient because it was hard to see what was happening. So where the white block is, is where the gradient is. – random Sep 27 '12 at 22:43
  • @sunkehappy The text is a UITextView that is not scrollable but is placed inside a UIScrollView. – random Sep 27 '12 at 22:43
  • Can you position the gradient above the UIScrollView/UITextView, so you don't have to move it? – Rob Reuss Sep 27 '12 at 23:00
  • @RobReuss I don't want to show the gradient if the scrollView is scrolled all the way to the top is the thing. – random Sep 28 '12 at 01:07
  • Can you set the gradient to hidden when scrollViewDidScroll tells you that you're near the top? – Rob Reuss Sep 28 '12 at 18:00
  • @RobReuss It's not a matter of how I show the gradient. It's the fact the `scrollViewDidScroll:(UIScrollView *)scrollView` isn't being called. – random Oct 01 '12 at 18:35
  • As you said in your final paragraph, maybe I'm going about this the wrong way. That's what I'm suggesting: that rather than trying to capture each point change in contentOffset, you take a different approach and layer your gradient on top of the whole thing. There are no guarantees that scrollViewDidScroll will get called for each point change. – Rob Reuss Oct 01 '12 at 19:05

0 Answers0