MBProgressHUD 动画

  1.   // Update to indeterminate indicator  
  2.             [indicator removeFromSuperview];  
  3.             self.indicator = MB_AUTORELEASE([[UIActivityIndicatorView alloc]  
  4.                                              initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]);  
  5.             self.indicator = MB_AUTORELEASE([[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 70, 40)]);  
  6.             self.indicator.contentMode = UIViewContentModeScaleAspectFit;  
  7. //          [(UIActivityIndicatorView *)indicator startAnimating];  
  8.             [self addSubview:indicator];  
  9.               
  10.             for (int i=0; i<24; i++) {  
  11.                 [_loadingArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"loading_%d",i + 1]]];  
  12.             }  
  13.               
  14.               
  15.             //设置动画数组  
  16.             [(UIImageView *)self.indicator setAnimationImages:_loadingArray];  
  17.             //设置动画播放次数  
  18.             [(UIImageView *)self.indicator setAnimationRepeatCount:MAXFLOAT];  
  19.             //设置动画播放时间  
  20.             [(UIImageView *)self.indicator setAnimationDuration:1.5];  
  21.             //开始动画  
  22.             [(UIImageView *)self.indicator startAnimating];  

 

 

 

 

 

 

 

 

 

现在很多APP的HUD已经都是自定义动画了,MBProgressHUD没有开放的API可以让我们直接使用,需要到.m文件中去修改源码。

首先在.m文件中找到

- (void)updateIndicators

方法在

if (mode == MBProgressHUDModeIndeterminate) {}

中自定义动画,然后上代码:

 

[plain] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <span style="font-size:18px;">if (mode == MBProgressHUDModeIndeterminate) {  
  2.         if (!isActivityIndicator) {  
  3.             // Update to indeterminate indicator  
  4.             [indicator removeFromSuperview];  
  5.             self.indicator = MB_AUTORELEASE([[UIActivityIndicatorView alloc]  
  6.                                              initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]);  
  7.             self.indicator = MB_AUTORELEASE([[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 70, 40)]);  
  8.             self.indicator.contentMode = UIViewContentModeScaleAspectFit;  
  9. //          [(UIActivityIndicatorView *)indicator startAnimating];  
  10.             [self addSubview:indicator];  
  11.               
  12.             for (int i=0; i<24; i++) {  
  13.                 [_loadingArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"loading_%d",i + 1]]];  
  14.             }  
  15.               
  16.               
  17.             //设置动画数组  
  18.             [(UIImageView *)self.indicator setAnimationImages:_loadingArray];  
  19.             //设置动画播放次数  
  20.             [(UIImageView *)self.indicator setAnimationRepeatCount:MAXFLOAT];  
  21.             //设置动画播放时间  
  22.             [(UIImageView *)self.indicator setAnimationDuration:1.5];  
  23.             //开始动画  
  24.             [(UIImageView *)self.indicator startAnimating];  
  25.         }  
  26. #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 50000  
  27.         if ([indicator isKindOfClass:[UIActivityIndicatorView class]]) {  
  28.             [(UIActivityIndicatorView *)indicator setColor:self.activityIndicatorColor];  
  29.         }  
  30.           
  31. #endif  
  32.     }</span>  


感兴趣的朋友可以尝试一下

 

 

回复hhhh23456789:我是把_loadingArray放在MB初始化方法里面声明的
- (id)initWithView:(UIView *)view {
NSAssert(view, @"View must not be nil.");
_loadingArray = [NSMutableArray array];
return [self initWithFrame:view.bounds];
}

 

posted @ 2016-07-15 09:33  zhen_zhen  阅读(212)  评论(0编辑  收藏  举报