如何随着滚动更改阿尔法值

我找不到任何地方这种粘滞issue.My的问题是,当用户开始滚动我需要更改alpha值。开始滚动alpha值应该是1,然后在滚动中间alpha值应为0.5,在结束它必须是0.这是我需要做的。我找不到用谷歌search。 帮助我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); }