如何更改alpha值以及滚动 [英] How to change alpha value along with scrolling

查看:140
本文介绍了如何更改alpha值以及滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到任何针对这种粘性问题的地方。我的问题是当用户开始滚动时我需要更改alpha值。滚动alpha值的开始应为1,然后在滚动alpha值的中间应该是0.5,最后它必须是0.这是我需要做的。我用谷歌搜索找不到。帮帮我PLZ

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

推荐答案

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

这篇关于如何更改alpha值以及滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆