简体   繁体   English

我如何做链接到uiscrollview contentoffest的uiimageView缩放动画?

[英]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). 我正在尝试实现将imageview缩放到scrollview偏移量的动画(我在Spotify和其他一些应用程序中看到了类似的东西)。 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 . 依此类推,直到值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? 什么是正确的方法?

Try setting the transform depending on the contentOffset without using animations, like 尝试根据contentOffset设置转换,而不使用动画,例如

- (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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM