gpt4 book ai didi

ios - 带有 gif 图像的 MBProgressHud

转载 作者:搜寻专家 更新时间:2023-10-30 20:13:52 35 4
gpt4 key购买 nike

我可以使用 gif 图像代替默认加载指示器吗?到目前为止,我正在使用这段代码,但没有得到任何结果。任何人都可以建议这段代码有什么问题吗?

#import "UIImage+GIF.h"
-(void) showLoadingHUD:(NSString *)title
{
[self hideLoadingHUD];
if(!HUD){
HUD = [MBProgressHUD showHUDAddedTo:self.window animated:YES];
}
[HUD setColor:[UIColor clearColor]];

UIImageView *imageViewAnimatedGif = [[UIImageView alloc]init];
imageViewAnimatedGif.image= [UIImage sd_animatedGIFNamed:@"martini_glass"];

HUD.customView = [[UIImageView alloc] initWithImage:imageViewAnimatedGif.image];
CABasicAnimation *rotation;
rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotation.fromValue = [NSNumber numberWithFloat:0];
rotation.toValue = [NSNumber numberWithFloat:(2 * M_PI)];
rotation.duration = 0.7f; // Speed
rotation.repeatCount = HUGE_VALF; // Repeat forever. Can be a finite number.
[HUD.customView.layer addAnimation:rotation forKey:@"Spin"];
HUD.mode = MBProgressHUDModeCustomView;
[HUD show:YES];
}

最佳答案

使用MBProgressHUD的最新库和 SDWebImage对于 "UIImage+GIF.h" 并且工作正常

-(void) showLoadingHUD:(NSString *)title {

[HUD hideAnimated:true];
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];

HUD.label.text = title;
HUD.bezelView.color = [UIColor clearColor];
UIImageView *imageViewAnimatedGif = [[UIImageView alloc]init];

//The key here is to save the GIF file or URL download directly into a NSData instead of making it a UIImage. Bypassing UIImage will let the GIF file keep the animation.
NSString *filePath = [[NSBundle mainBundle] pathForResource: @"loader" ofType: @"gif"];
NSData *gifData = [NSData dataWithContentsOfFile: filePath];
imageViewAnimatedGif.image = [UIImage sd_animatedGIFWithData:gifData];

HUD.customView = [[UIImageView alloc] initWithImage:imageViewAnimatedGif.image];
CABasicAnimation *rotation;
rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotation.fromValue = [NSNumber numberWithFloat:0];
rotation.toValue = [NSNumber numberWithFloat:(2 * M_PI)];
rotation.duration = 0.7f; // Speed
rotation.repeatCount = HUGE_VALF; // Repeat forever. Can be a finite number.
rotation.removedOnCompletion = false;
[HUD.customView.layer addAnimation:rotation forKey:@"Spin"];
HUD.mode = MBProgressHUDModeCustomView;
HUD.contentColor = [UIColor redColor];
[HUD showAnimated:YES];
}

示例加载器 .gif 图像: loader

关于ios - 带有 gif 图像的 MBProgressHud,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42359456/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com