1

我正在使用以下内容使 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);
}];

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

4

3 回答 3

0

查看有关 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

于 2013-07-03T00:34:51.467 回答
0

这可以解决问题:

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

}];
于 2013-07-03T00:39:04.560 回答
0

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

[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);
    }];
}];
于 2013-07-03T00:50:38.687 回答