I have a UIPageControl
that flips through different pages. I'd like to have a UIImageView begin to fade as the user scrolls from page 1 to page 2. I'm struggling trying to figure out the proper way to add a layer based on the position. Any help would be most appreciated...
[UIView beginAnimations:@"fade out" context:nil];
[UIView setAnimationDuration:1.0]; // some how based on position??
imageView.alpha = 1.0; // here to?
[UIView commitAnimations];
Edit:
Set the delegate:
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageController.dataSource = self;
You need the delegate to override the following method:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
Then you should check against the scrollView.contentOffset.x
value to determine how much the scroll view has scrolled horizontally, and use it to determine your imageView's alpha as follows:
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With