在UIImageView动画中应用一些缓和



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

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

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

[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 animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionCurveEaseInOut       animations:^(void){
//do your animations
} completion:^(BOOL finished){
}];

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

最新更新