【问题标题】:Apply some easing into UIImageView animation对 UIImageView 动画应用一些缓动
【发布时间】:2013-07-03 00:29:16
【问题描述】:

我正在使用以下方法使 UIImageView 向前滑动一点,然后再向后滑动更远以获得视差滚动效果。

代码:

[UIView animateWithDuration:0.2f animations:^{
    spendrBckGrnd.frame = CGRectMake(spendrBckGrnd.frame.origin.x + 20, 0, spendrBckGrnd.frame.size.width, spendrBckGrnd.frame.size.height);
}];
[UIView animateWithDuration:0.4f animations:^{
    spendrBckGrnd.frame = CGRectMake(spendrBckGrnd.frame.origin.x - 80, 0, spendrBckGrnd.frame.size.width, spendrBckGrnd.frame.size.height);
}];

我想知道如何在动画中应用一些缓动,如果只是突然快速地来回滑动。我想轻松进出滑动动画。

【问题讨论】:

    标签: ios objective-c


    【解决方案1】:

    您需要在第一个动画块完成后执行第二个动画块。

    [UIView animateWithDuration:0.2f animations:^{
        spendrBckGrnd.frame = CGRectMake(spendrBckGrnd.frame.origin.x + 20, 0, spendrBckGrnd.frame.size.width, spendrBckGrnd.frame.size.height);
    } completion:^{
        [UIView animateWithDuration:0.2f animations:^(BOOL finished){
            spendrBckGrnd.frame = CGRectMake(spendrBckGrnd.frame.origin.x - 80, 0, spendrBckGrnd.frame.size.width, spendrBckGrnd.frame.size.height);
        }];
    }];
    

    【讨论】:

    • 就是这样,不敢相信我没有从 UIView 中捕获其他静态方法。顺便说一句,您的代码就像我需要的那样工作,但是您需要将(BOOL 完成)添加到我相信的第二个块
    【解决方案2】:

    这样就可以了:

    [UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionCurveEaseInOut       animations:^(void){
    //do your animations
    } completion:^(BOOL finished){
    
    }];
    

    【讨论】:

      【解决方案3】:

      查看这个关于 UIView 动画的教程 http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_uiview-animations/

      UIView 有一个方法

      //   [UIView animateWithDuration:(NSTimeInterval) delay:(NSTimeInterval) options:(UIViewAnimationOptions)animations:^(void)animations completion:^(BOOL finished)completion];
      typedef enum {
              UIViewAnimationCurveEaseInOut,         // slow at beginning and end
              UIViewAnimationCurveEaseIn,            // slow at beginning
              UIViewAnimationCurveEaseOut,           // slow at end
              UIViewAnimationCurveLinear
          }
          [UIView animateWithDuration:0.6f
                      delay:0.1f
                      options:UIViewAnimationCurveEaseInOut
                      animations:^{
                              [starView setCenter:CGPointMake(0, 0)];
                              [starView setAlpha:0.0f];
                      }
                      completion:^(BOOL finished){
                                  [starView removeFromSuperview];
                                  points++;
                      }
          ]; 
      

      还可以查看 github 上的此控件,该控件使用自定义容器视图创建视差效果,非常类似于 Path 时间轴的顶视图。 https://github.com/modocache/MDCParallaxView

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-06-16
        • 1970-01-01
        • 2012-04-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多