gpt4 book ai didi

ios - 基于 ScrollView Position 的 UIImageView Fading

转载 作者:可可西里 更新时间:2023-11-01 04:23:46 25 4
gpt4 key购买 nike

我有一个 UIPageControl 可以翻阅不同的页面。当用户从第 1 页滚动到第 2 页时,我想让 UIImageView 开始淡出。我正在努力找出根据位置添加图层的正确方法。任何帮助将不胜感激...

[UIView beginAnimations:@"fade out" context:nil];
[UIView setAnimationDuration:1.0]; // some how based on position??
imageView.alpha = 1.0; // here to?
[UIView commitAnimations];

编辑:

设置委托(delegate):

 self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];

self.pageController.dataSource = self;

最佳答案

您需要委托(delegate)重写以下方法:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView;

然后您应该检查 scrollView.contentOffset.x 值以确定 ScrollView 水平滚动了多少,并使用它来确定您的 imageView 的 alpha,如下所示:

CGFloat newAlpha = scrollView.contentOffset.x / scrollView.frame.size.width; // This will need to be adapted depending on the content size of your scroll view -- do not just copy and paste this expecting it to work :)
imageView.alpha = newAlpha;

关于ios - 基于 ScrollView Position 的 UIImageView Fading,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18245647/

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