ios - 如何随着滚动改变 alpha 值

标签 ios objective-c uiscrollview

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

最佳答案

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

关于ios - 如何随着滚动改变 alpha 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25263343/

相关文章:

ios - 在 TableView 单元格选择上打开 URL(RSS 阅读器)

ios - 尝试在框架目标中导入 Sinch 时出现 'Include of non-modular header'

ios - 在 UICollectionView 的底部加载额外的单元格

ios - 共享扩展 - 未调用 beginRequestWithExtensionContext

ios - 仅将一些触摸事件从一个 View 传递到另一个 View

ios - ScrollView 不水平滚动

ios - UIScrollView ContentSize 高度太大

ios - 前锋准备进入无限循环

ios - 将 block 并发插入并发队列

objective-c - 什么是 ObjectiveC.gcno?它应该包含在源代码存储库中吗?