UIScrollView scrollViewDidScroll没有触发

时间:2012-09-26 22:32:37

标签: objective-c ios uiscrollview uiscrollviewdelegate

我有一个UIScrollView,里面有一堆文字。当用户向上滚动时,我在顶部创建了一个小的颜色到透明的视图,因此文本看起来不像它只是掉落。

我让scrollView正常工作,委托设置等等。

这一切都很好,花花公子,我得到了这个(这就是我想要的):

滚动前:

enter image description here

当我开始向下滚动时,它会像它假设的那样增长:

enter image description here

当我向上滚动时,它会缩小,就像它假设的那样:

enter image description here


问题: 然而!如果我快速向上轻拂,似乎scrollViewDidScroll:(UIScrollView *)scrollView没有被足够快地调用,并且渐变的帧永远不会更新。是否有另一个我需要检查的scollView委托方法?或者我可能会以错误的方式处理渐变。

enter image description here


以下是处理更新渐变框架的scrollViewDidScroll:(UIScrollView *)scrollView方法:

- (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;
    }
}

0 个答案:

没有答案