ios - 基于 ScrollView Position 的 UIImageView Fading

标签 ios objective-c

我有一个 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/

相关文章:

ios - Swift 3 - 如何将 UISwitch 的当前值存储在 UITableViewCell 中,实际 ViewController 的变量中?

ios - 无法导入桥接头错误

ios - 按下按钮后如何修改 View Controller ?

ios - 什么时候请求推送通知?

iphone - tableView cellForRowAtIndexPath 最初被多次调用

ios - 我无法在 Swift 中解决 "Use of undeclared type ' SphereNode'"

ios - 带有 CIQRCodeGenerator 的 CIFilter 导致崩溃

ios - 如何在请求中使用 NSStrings 映射 NSArray (RESTKit)

ios - 在ARC中,子对象如何告诉父对象我已经完成,请释放我(以避免内存泄漏)

php - 在 Objective C 中从 URL 下载 JSON 的简单方法