0

这是我用来获取 aUIImageView并使其上下浮动的代码。

    [UIView animateKeyframesWithDuration:2.0 delay:0.0 options:UIViewKeyframeAnimationOptionRepeat animations:^{
        [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.25 animations:^{
            self.slider.transform = CGAffineTransformMakeTranslation(0, -5.0);
        }];
        [UIView addKeyframeWithRelativeStartTime:0.25 relativeDuration:0.5 animations:^{
            self.slider.transform = CGAffineTransformMakeTranslation(0, 5.0);
        }];
        [UIView addKeyframeWithRelativeStartTime:0.75 relativeDuration:0.25 animations:^{
            self.slider.transform = CGAffineTransformMakeTranslation(0, 0.0);
        }];
    } completion:^(BOOL finished) {

    }];

但是,在动画结束后和重新启动之前,它会出现这种延迟。

我如何使它变得流畅?

4

1 回答 1

1

我不确定你到底想要什么效果,但我认为这会给你一些类似你的代码没有延迟的东西。我通常通过动画约束来做到这一点,而不是使用变换。在此示例中,我为视图顶部的约束创建了一个 IBOutlet (topCon):

-(IBAction)floatView:(id)sender {
    static int i= 1;
    static float duration = .25;
    [UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
        self.topCon.constant = self.topCon.constant - (5 * i);
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        i = (i == 1 || i == 2)? -2 : 2;
        duration = 0.5;
        [self floatView:self];
    }];
}
于 2013-11-01T05:10:59.657 回答