ios UIProgressView 控制进度完成时间

外侧需要多套一层动画,否者进度会立刻完成

+ (void)progressView:(UIProgressView *)progressView progressFinishInTime:(NSTimeInterval)interval {
    
    
    [UIView animateWithDuration:0
                     animations:^{
    
    
        [progressView layoutIfNeeded];
    }
                     completion:^(BOOL finished) {
    
    
        progressView.progress = 1.0;
        [UIView animateWithDuration:interval
                              delay:0
                            options:UIViewAnimationOptionCurveLinear
                         animations:^{
    
    
            [progressView layoutIfNeeded];
        }
                         completion:^(BOOL finished) {
    
    
            //动画完成
        }];
    }];
}

如果在viewDidload等 view还没渲染好的时候调用,还是可能异常,可以这样:

 UIProgressView *progressView = [UIProgressView new];
 //中间省略属性配置。。。。。。
    dispatch_async(dispatch_get_main_queue(), ^{
    
    
        [[self class] progressView:progressView progressFinishInTime:3];
 });

猜你喜欢

转载自blog.csdn.net/htwhtw123/article/details/127463697