我找不到这种棘手问题的任何地方。我的问题是当用户开始滚动时我需要更改 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/