Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change alpha value along with scrolling

I could not found any where for this kind sticky issue.My issue is when the user started scrolling i need to change the alpha value.At starting of scrolling alpha value should be 1, then at middle of scrolling alpha value should be 0.5, at end it must be 0.This what i need to do.i could not find with googling. help me plz

like image 586
Code cracker Avatar asked Nov 28 '22 20:11

Code cracker


1 Answers

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    /* This is the offset at the bottom of the scroll view. */
    CGFloat totalScroll = scrollView.contentSize.height - scrollView.bounds.size.height;

    /* This is the current offset. */
    CGFloat offset = - scrollView.contentOffset.y;

    /* This is the percentage of the current offset / bottom offset. */
    CGFloat percentage = offset / totalScroll;

    /* When percentage = 0, the alpha should be 1 so we should flip the percentage. */
    scrollView.alpha = (1.f - percentage);
}
like image 91
cutsoy Avatar answered Dec 12 '22 13:12

cutsoy