5

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

编辑:

设置委托:

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

    self.pageController.dataSource = self;
4

1 回答 1

9

您需要委托来覆盖以下方法:

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

然后您应该检查该scrollView.contentOffset.x值以确定滚动视图水平滚动了多少,并使用它来确定您的 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;
于 2013-08-15T03:07:14.680 回答