Reputation:
I'm developing an iOS app and i have a full screen UIScrollView with a UIImageView at the top and 2 UIButton in the bottom.
When the user scrolls i want to insert an animation on the image view (maybe only change the alpha parameter gradually).
The animation is correlated with the scrollview, for example, if the user scrolls the scrollview half, will be displayed only half animation.
I hope I explained myself.
How can i do this?
Upvotes: 1
Views: 886
Reputation: 2387
Use the UIScrollViewDelegate scrollViewDidScroll:
method.
But also check out other methods in that delegate.
So for example, you may end up with something like (or change this to your needs):
-(void)scrollViewDidScroll:(UIScrollView*)scrollView {
float opacity = ( 100 - scrollView.contentOffset.y ) / 100.0;
opacity = (opacity < 0? 0 : opacity>1? 1 : opacity);
imageView.layer.opacity = opacity;
}
You might also want to learn from Apple engineers themselves. Check out the WWDC videos, there are many of them:
Upvotes: 2
Reputation: 193
Implement the UIScrollView
Delegate protocol and use this method
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
}
Here you can change the alpha value of your UIImageView
by adjusting the opacity of the view's layer:
imageView.layer.opacity = ...
That's called an implicit animation.
Upvotes: 0