// // LoadingView.m // test11113 // // Created by apple on 15/11/11. // Copyright (c) 2015年 JCZ. All rights reserved. // #import "ActivityView.h" #import "LoadingView.h" #import "STButton.h" #import static LoadingView* myView ; // //static STButton* msgBtn; static NSMutableArray* msgArr; /**用来播放水滴声音的 */ static AVAudioPlayer* player; #define HUD_Frame [[UIScreen mainScreen] bounds] #define HUD_Size HUD_Frame.size @interface LoadingView() @property(nonatomic,strong)UILabel* label; @property(nonatomic,strong)ActivityView* indicator; @end @implementation LoadingView -(id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor colorWithRed:134/255.0 green:204/255.0 blue:71/255.0 alpha:.1]; self.backgroundColor = [UIColor colorWithWhite:.9 alpha:.45]; // self.layer.cornerRadius = 50; // self.layer.masksToBounds = YES; _indicator = [[ActivityView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; _indicator.center = CGPointMake(50, 50); [_indicator startAnimating]; [self addSubview:_indicator]; _label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_indicator.frame), _indicator.frame.origin.y, HUD_Size.width, 100)]; _label.textColor = [UIColor orangeColor]; _label.font = [UIFont scaleSize:30]; [self addSubview:_label]; } return self; } +(void)createHUD { //如果是后台 就不在展示弹出框了 if (myDelegate.isBackgroundTask) { return; } @try { if (!myView) { myView = [[LoadingView alloc] initWithFrame:CGRectMake((kSize.width - 100)/2.0, (kSize.height - 100)/2.0, 100, 100)]; NSString * path = [[NSBundle mainBundle] pathForResource:@"toast.wav" ofType:nil]; NSFileManager* fm = [NSFileManager defaultManager]; if (![fm fileExistsAtPath:path]) { return; } //crash dansonmark 从本地获取音频播放crash 我猜是线程出问题了 这个问题不是必现的 NSURL * url = [NSURL fileURLWithPath:path]; player =[[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil]; player.volume = 1; player.numberOfLoops =0; } } @catch (NSException *exception) { } @finally { } } /**如果真机上遇到MSG无法消除的问题。可以考虑用数组保存label。然后遍历数组移除。 guide_icon7 */ +(void)showMsg:(NSString*)str { //如果是后台 就不在展示弹出框了 if (myDelegate.isBackgroundTask) { return; } dispatch_async(dispatch_get_main_queue(), ^{ CGFloat w,h; w = 200; h = 130; if (!msgArr) { msgArr = [NSMutableArray array]; } for (UIView* v in msgArr) { [v removeFromSuperview]; } STButton* msgBtn = [[STButton alloc] initWithFrame:CGRectMake(0,0, w, h)]; // [msgBtn setStyle:2]; msgBtn.center = CGPointMake(kSize.width/2.0, kSize.height/2.0); msgBtn.backgroundColor = RGB_COLOR(255, 215, 10); msgBtn.titleLabel.numberOfLines = 0; [msgBtn setTitle:str textColor:RGB_COLOR(24, 19, 18) font:20 fotState:UIControlStateNormal]; [msgArr addObject:msgBtn]; msgBtn.layer.cornerRadius = 5; msgBtn.layer.masksToBounds = YES; msgBtn.backgroundColor = [UIColor colorWithWhite:1 alpha:.8]; [msgBtn setImage:[UIImage imageNamed:@"question_correct.png"] forState:UIControlStateNormal]; [[UIApplication sharedApplication].delegate.window addSubview:msgBtn]; [player play]; [UIView animateWithDuration:2.5 animations:^{ msgBtn.alpha = .7; }completion:^(BOOL finished) { [msgBtn removeFromSuperview]; }]; }); } /**0是普通的警告。1是操作成功的 */ +(void)showMsg:(NSString *)str Style:(int)style { //如果是后台 就不在展示弹出框了 if (myDelegate.isBackgroundTask) { return; } dispatch_async(dispatch_get_main_queue(), ^{ CGFloat w,h; w = 200; h = 130; if (!msgArr) { msgArr = [NSMutableArray array]; } for (UIView* v in msgArr) { [v removeFromSuperview]; } STButton* msgBtn = [[STButton alloc] initWithFrame:CGRectMake(0,0, w, h)]; msgBtn.center = CGPointMake(kSize.width/2.0, kSize.height/2.0); if (0 == style) { msgBtn.backgroundColor = RGB_COLOR(255, 215, 10); [msgBtn setImage:[[UIImage imageNamed:@"guide_icon7.png"] tint:RGB_COLOR(24, 19, 18)] forState:UIControlStateNormal]; }else{ msgBtn.backgroundColor = [UIColor colorWithWhite:1 alpha:.8]; [msgBtn setImage:[UIImage imageNamed:@"question_correct.png"] forState:UIControlStateNormal]; } msgBtn.titleLabel.numberOfLines = 0; [msgBtn setTitle:str textColor:RGB_COLOR(24, 19, 18) font:20 fotState:UIControlStateNormal]; [msgArr addObject:msgBtn]; msgBtn.layer.cornerRadius = 5; msgBtn.layer.masksToBounds = YES; [[UIApplication sharedApplication].keyWindow addSubview:msgBtn]; [player play]; [UIView animateWithDuration:2 animations:^{ msgBtn.alpha = .9; }completion:^(BOOL finished) { [msgBtn removeFromSuperview]; }]; }); } +(void)showHUD{ dispatch_async(dispatch_get_main_queue(), ^{ [LoadingView createHUD]; [myView.indicator startAnimating]; [[UIApplication sharedApplication].keyWindow addSubview:myView]; }); } +(void)removeHUD { dispatch_async(dispatch_get_main_queue(), ^{ //如果都存在 在除掉 if(myView || myView.superview){ [myView.indicator stopAnimating]; [myView removeFromSuperview]; } }); } @end @implementation InputView -(id)initWithTitle:(NSString*)title{ self = [super initWithFrame:kFrame]; [self setBackgroundColor:[UIColor colorWithWhite:.3 alpha:.6]]; if (self) { CGFloat x,y,w,h,bd; w = 280; x = (kSize.width - w)/2.0; y=0; h = 120; UIView* cv = [[UIView alloc] initWithFrame:CGRectMake(x, y, w, h)]; [cv setBackgroundColor:[UIColor whiteColor]]; [self addSubview:cv]; cv.layer.cornerRadius = 10; cv.layer.masksToBounds = YES; [cv setClipsToBounds:YES]; contentVi = cv; UILabel* label; int num = 4; int cnt = 10; bd = 15; h = (contentVi.width - (num+1)*bd)/num; x=0; y=0; // w=w; // h=30; label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)]; [label setBackgroundColor:defGreen]; [label setTextColor:[UIColor whiteColor]]; [label setText:title]; [label setTextAlignment:NSTextAlignmentCenter]; [cv addSubview:label]; UIButton* btn; NSInteger tag=0; bd = 10; w = h; x = cv.width - bd - w; btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, w, h)]; [btn setTitle:@"×" textColor:[UIColor whiteColor] font:30 fotState:UIControlStateNormal]; [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside]; [cv addSubview:btn]; [btn setTag:tag++]; //port 1 -10 num = 4; cnt = 10; bd = 15; w = (contentVi.width - (num+1)*bd)/num; y+= h + bd; h = w; for (int i = 0; i