0

因此,我有一张图像,用于向用户显示在他们点击按钮后正在执行同步,但无法弄清楚如何让它保持旋转几秒钟而不是一次....以下是我用来执行动画的方法。有人可以帮我弄清楚如何让它旋转几秒钟吗?

提前致谢!

- (void)syncTapped:(UIButton *)standardButton {
    [self animateSynchronization];
    repeatSyncAnimation = YES;
}


-(void)animateSynchronization {
    repeatSyncAnimation = YES;
    [UIView animateWithDuration:0.23 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
        syncImage.transform = CGAffineTransformRotate(syncImage.transform, M_PI_2);
    } completion:^(BOOL finished){
        if (repeatSyncAnimation) {
            [self animateSynchronization];
            [self stopSynchronizationAnimation];
        }
    }];
}
4

1 回答 1

1

您可以消除该completion块并仅使用该UIViewAnimationOptionRepeat选项(以及您现有的UIViewAnimationOptionCurveLinear选项)。当你想停止动画时,你可以:

[syncImage.layer removeAllAnimations];

显然,如果您希望在预定时间后停止,您可以使用 aNSTimerdispatch_after,例如:

double delayInSeconds = 5.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [syncImage.layer removeAllAnimations];
});

#import但是,您必须在文件的开头添加一个.m,以便编译器识别此removeAllAnimations方法:

#import <QuartzCore/QuartzCore.h>
于 2013-06-03T23:29:04.303 回答