123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- //
- // 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 <AVFoundation/AVFoundation.h>
- 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<cnt; i++)
- {
- x = (bd+w)*(i%num)+bd;
- btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, w, h)];
- NSString* path = [NSString stringWithFormat:@"portrait%d.png",i+1];
- [btn setImage:[UIImage imageNamed:path] forState:UIControlStateNormal];
- [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- [btn setBackgroundColor:defGreen];
- [contentVi addSubview:btn];
- btn.layer.cornerRadius = 5;
- btn.layer.masksToBounds = YES;
-
- [btn setTag:tag++];
- if ( 0 == (i+1)%num)
- {
- y += h + bd ;
- }
- }
- x = 0;
- w = contentVi.width*.5;
- if ( 0 != cnt%num)
- {
- y += h + bd ;
- }
- btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [btn setTitle:@"相册" textColor:defGreen font:20 fotState:UIControlStateNormal];
- [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- [contentVi addSubview:btn];
- [btn setTag:tag++];
-
- x += w;
- btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [btn setTitle:@"拍照" textColor:defGreen font:20 fotState:UIControlStateNormal];
- [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- [contentVi addSubview:btn];
- [btn setTag:tag++];
-
- contentVi.height = y+ h;
- contentVi.center = self.center;
- }
- return self;
- }
- -(void)btnClick:(UIButton*)sender
- {
- //NSLog(@"btn%d",(int)sender.tag);
- if (sender.tag < 1) {
- [self cancelAction];
- }else if (sender.tag < 11){
- NSString* path = [NSString stringWithFormat:@"portrait%d.png",(int)sender.tag];
- if (_delegate && [_delegate respondsToSelector:@selector(InputView:didGetImage:)]) {
- [_delegate InputView:self didGetImage:[UIImage imageNamed:path]];
- [self cancelAction];
- }
- return;
- }
- if ( 11 == sender.tag){
- self.type = 0;
- if (_delegate && [_delegate respondsToSelector:@selector(InputViewWillPickImage:)]) {
- [_delegate InputViewWillPickImage:self];
- [self removeFromSuperview];
- }
- return;
- }
- if ( 12 == sender.tag){
- self.type = 1;
- if (_delegate && [_delegate respondsToSelector:@selector(InputViewWillPickImage:)]) {
- [_delegate InputViewWillPickImage:self];
- [self removeFromSuperview];
- }
- return;
- }
- }
- -(void)show
- {
- [[UIApplication sharedApplication].keyWindow addSubview:self];
- contentVi.transform = CGAffineTransformScale(contentVi.transform, .3, .3);
- self.alpha = .1;
- [UIView animateWithDuration:.5 animations:^{
- self.alpha = 1;
- contentVi.transform = CGAffineTransformIdentity;
- } ];
- }
- -(void)cancelAction
- {
- self.userInteractionEnabled = NO;
- [UIView animateWithDuration:.5 animations:^{
- self.alpha = .1;
- contentVi.transform = CGAffineTransformScale(contentVi.transform, .3, .3);
- } completion:^(BOOL finished) {
- [self removeFromSuperview];
- }];
- }
- @end
- #pragma mark -
- void ShowHUD()
- {
- [LoadingView showHUD];
- }
- void showHUDTitle(NSString* title)
- {
- ShowHUD();
- [myView.label setText:title];
- }
- void RemoveHUD()
- {
- [LoadingView removeHUD];
- }
- void ShowMsg(NSString* str)
- {
- [LoadingView showMsg:str];
- }
- void ShowMsgEmpty(){
- [LoadingView showMsg:@"暂无信息"];
- }
- void showMsgUnconnect(){
- [LoadingView showMsg:@"网络未连接"];
- RemoveHUD();
- }
- void showMsgLoginPls(){
- [LoadingView showMsg:@"请登录后操作"];
- }
- void ShowMsgUnOpen()
- {
- [LoadingView showMsg:@"暂未开放,敬请期待"];
- }
- void ShowMsgFailed()
- {
- [LoadingView showMsg:@"操作失败"];
- }
- void ShowMsgSuc()
- {
- [LoadingView showMsg:@"操作成功" Style:1];
- }
|