MBProgressHud添加自定義動畫


在使用自定義view時,若直接使用,如下

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.label.text = @"加載中…"; hud.mode = MBProgressHUDModeCustomView; UIImage *image = [[UIImage imageNamed:@"toast_loading"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; UIImageView *imgView = [[UIImageView alloc] initWithImage:image]; hud.customView = imgView; hud.bezelView.color = [UIColor colorWithWhite:0.0 alpha:1]; //文字顏色
hud.contentColor = [UIColor whiteColor]; hud.animationType = MBProgressHUDAnimationFade;

那么效果為

若想使自定義view有動態效果,那么需要對UIImageView添加動畫

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.label.text = @"加載中…"; hud.mode = MBProgressHUDModeCustomView; UIImage *image = [[UIImage imageNamed:@"toast_loading"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; UIImageView *imgView = [[UIImageView alloc] initWithImage:image]; CABasicAnimation *anima = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; anima.toValue = @(M_PI*2); anima.duration = 1.0f; anima.repeatCount = 10; [imgView.layer addAnimation:anima forKey:nil]; hud.customView = imgView; hud.bezelView.color = [UIColor colorWithWhite:0.0 alpha:1]; //文字顏色
hud.contentColor = [UIColor whiteColor]; hud.animationType = MBProgressHUDAnimationFade;

此時效果為

最后補充,若想設置hud大小,可以用

hud.minSize = CGSizeMake(165,90);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM