Reputation: 1145
I'm trying to achive an animation that zoom an imageview accordingly to a scrollview offset (i have seen something similar in spotify and some others apps). How i can do? I have tried something like:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (Scroll.contentOffset.y<-10 && Scroll.contentOffset.y>-20) {
[UIView animateWithDuration:0.1
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:(void (^)(void)) ^{
ImageView.transform=CGAffineTransformMakeScale(1.1, 1.1);
}
completion:^(BOOL finished){
}];
}
if (Scroll.contentOffset.y<-20 && Scroll.contentOffset.y>-30) {
[UIView animateWithDuration:0.1
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:(void (^)(void)) ^{
ImageView.transform=CGAffineTransformMakeScale(1.2, 1.2);
}
completion:^(BOOL finished){
}];
}
}
and so on until a value of 1.6 . Naturally this methods doesn't works well, it is called to many times and visually it jitters... I wanto to achive this result: The user scroll down the scrollview while an image view placed in the background is scaled until an arbitray value (and a reverse behaviour when the user returns to scroll up). What is a correct approch?
Upvotes: 0
Views: 606
Reputation: 2842
Try setting the transform depending on the contentOffset without using animations, like
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat scale = 1;
if(Scroll.contentOffset.y<0){
scale -= Scroll.contentOffset.y/10; //calculate the scale factor as you like
}
ImageView.transform = CGAffineTransformMakeScale(scale,scale);
}
Upvotes: 4