簡體   English   中英

創建動畫以使UIImageView無限向上和向下(幾乎浮動)時,如何在動畫結束時停止暫停?

[英]When creating an animation to cause a UIImageView to go up and down (almost float) infinitely, how do I stop a pause at the end of the animation?

這是我用來獲取UIImageView並使它上下浮動的代碼。

    [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) {

    }];

但是,在動畫結束之后和重新開始之前,延遲一段時間后看起來像這樣。

我如何使其流暢?

我不確定您到底要達到什么效果,但是我認為這可以為您提供類似於代碼的效果而不會延遲。 我通常通過設置約束動畫來實現此目的,而不是使用變換。 在此示例中,我對視圖頂部的約束做了一個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];
    }];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM