mardi 27 janvier 2015

How i can do an uiimageView zoom animation linked to uiscrollview contentoffest?

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?




Aucun commentaire:

Enregistrer un commentaire