gpt4 book ai didi

ios - 滚动时更改按钮的 alpha

转载 作者:行者123 更新时间:2023-11-28 13:09:38 25 4
gpt4 key购买 nike

我有两个按钮,我想在水平滚动 2 个 View 时更改它们的 alpha。

我希望一个按钮以 0.3 alpha 开始,另一个以 1.0 开始。当我滚动到另一个 View 时,我希望它们切换值:第一个按钮为 1.0,第二个按钮为 0.3。

我只是在 scrollViewDidScroll 委托(delegate)中玩了一个按钮:

 allBtn.alpha = scrollView.contentOffset.x / scrollView.bounds.size.width * 0.3

滚动后我会有 0.3 的 alpha,但是当我返回时,它将是 0。

知道如何正确执行此操作吗?

最佳答案

- (CGFloat)calculateButtonAlphaUsingScrollView:(UIScrollView *)scrollView withAlphaForOffsetZero:(CGFloat)alphaForOffsetZero withAlphaForOffsetMax:(CGFloat)alphaForOffsetMax {
CGFloat width = scrollView.frame.size.width;
CGFloat contentWidth = scrollView.contentSize.width;
CGFloat scrollLength = contentWidth - width;
CGFloat scrollOffset = scrollView.contentOffset.x;
CGFloat scrollValue = scrollOffset / scrollLength;
CGFloat alphaChange = alphaForOffsetMax - alphaForOffsetZero;
return alphaForOffsetZero + alphaChange * scrollValue;
}

关于ios - 滚动时更改按钮的 alpha,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31839540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com