libpag icon indicating copy to clipboard operation
libpag copied to clipboard

IOS使用异步加载资源时,会阻塞主线程

Open KitsGithub opened this issue 10 months ago • 0 comments

【版本信息】

4.3.62

【平台信息】

iOS 原生

【预期的表现】

正常无卡顿现象

【实际的情况】

异步加载网络资源的时候,当PAG文件较大时,先报

file open failed! filePath:/var/mobile/Containers/Data/Application/9F952709-DF20-4478-8F39-33A845534F66/Library/Caches/libpag/files/1.bin 

然后阻塞主线程导致卡顿,等待下载完成后,才可以继续往下

【Demo及附件】

在官方demo中,修改PAGImageViewTableViewController.m:29-36行为以下代码

- (void)setFilePath:(NSString *)filePath {
    if ([filePath length] > 0) {
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_global_queue(0, 0), ^{
            [self.pagImageView setPathAsync:@"https://cybercharge-admin.s3.ap-southeast-1.amazonaws.com/admin/images/pag_path6853e158d4ff6.pag" completionBlock:^(PAGFile * _Nonnull) {
                [self.pagImageView play];
            }];
        });
        
//        [self.pagImageView setPath:filePath];
        [self.pagImageView setCurrentFrame:0];
        [self.pagImageView setRepeatCount:-1];
//        [self.pagImageView play];
    }
}

KitsGithub avatar Jun 23 '25 04:06 KitsGithub