调用方法:
如:[UIAnimationTool ShowAlert:@"分享失败!"];
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, UIErrAnimationType){
ENotSupportOffline = 1,//不支持离线模式
EProtocolFormatError = 7,//协议格式错误
EUnknownFormat = 6,//未知格式
ENotSupportFormat = 5,//不支持格式
ENothing =4,//对获取数据的请求处理正确,但没有符合条件的结果返回
EPartialContent = 3,//只返回了请求数据中的一部分
ENetTimeout = 2,//请求超时
ENetDisconnect = 1,//网络连接异常
ESuccess = 0,//成功
EUnknownError = -1,//服务器发生未定义的错误
EUserOrPassError = -10,//用户名或密码错误
EVersionError = -3,//版本不被服务器支持
EKicked = -4, //被T了
ESmscode = -5,//短信授权码不正确
ECer = -6, //登录签证不正确
EAlreadyDone = -7, //已完成,已提交
EParams = -8, //参数错误
EUserusing = -12,//用户已经登录,不允许重复登录
#import "UIAnimationTool.h"
@implementation UIAnimationTool
static UIActivityIndicatorView* g_activityView;
static UIAlertView *g_aniAlert;
#define stopActiveAnimation {[g_activityView stopAnimating]; g_activityView=nil;}
+(void)ShowActivityIndicator:(UIView*)view
{
if(view == nil)
return;
stopActiveAnimation;
if(!g_activityView)
{
g_activityView = [[UIActivityIndicatorViewalloc]
initWithFrame:CGRectMake(0,
0.0f,
20,
20)];
g_activityView.activityIndicatorViewStyle =UIActivityIndicatorViewStyleGray;
g_activityView.autoresizingMask =UIViewAutoresizingFlexibleLeftMargin
| UIViewAutoresizingFlexibleRightMargin
| UIViewAutoresizingFlexibleTopMargin
| UIViewAutoresizingFlexibleBottomMargin;
g_activityView.hidesWhenStopped =YES;
[g_activityViewstartAnimating];//开启动画
}
[g_activityView setFrame:CGRectMake((view.frame.size.width-20)/2, (view.frame.size.height-20)/2,20,20)];
[view addSubview:g_activityView];
}
+(void)ShowActivityIndicator:(UIView*)view at:(CGPoint)pos
{
stopActiveAnimation;
if(!g_activityView)
{
g_activityView = [[UIActivityIndicatorViewalloc]
initWithFrame:CGRectMake(0,
0.0f,
20,
20)];
g_activityView.activityIndicatorViewStyle =UIActivityIndicatorViewStyleGray;
g_activityView.autoresizingMask =UIViewAutoresizingFlexibleLeftMargin
| UIViewAutoresizingFlexibleRightMargin
| UIViewAutoresizingFlexibleTopMargin
| UIViewAutoresizingFlexibleBottomMargin;
g_activityView.hidesWhenStopped =YES;
[g_activityViewstartAnimating];//开启动画
}
[g_activityView setFrame:CGRectMake(pos.x -10, pos.y -10,20, 20)];
[view addSubview:g_activityView];
}
+(void)DisimissActivityIndicator
{
stopActiveAnimation;
}
+(void)ShowError:(int)Result
{
if (Result == ENetTimeout) {
[self ShowAlert:@"请求超时"];
}else if (Result ==EUserusing) {
[selfShowAlert:@"用户已经登录,不允许重复登录"];
}else if (Result ==ENetDisconnect) {
[self ShowAlert:@"网络连接异常"];
}else if (Result ==EVersionError) {
[self ShowAlert:@"版本不被服务器支持"];
}else if(Result ==EProtocolFormatError) {
[self ShowAlert:@"协议格式错误"];
}else if(Result ==EUnknownFormat) {
[self ShowAlert:@"未知格式"];
}else if(Result ==ENotSupportFormat) {
[self ShowAlert:@"不支持格式"];
}else if(Result ==EPartialContent) {
[selfShowAlert:@"只返回了请求数据中的一部分"];
}else if(Result ==EUserOrPassError) {
[self ShowAlert:@"用户名或密码错误"];
}else if(Result ==EUnknownError) {
[self ShowAlert:@"服务器异常"];
}else {
[self ShowAlert:@"未知错误"];
}
}
+(void)ShowAlert:(NSString *) text
{
if(g_aniAlert!=nil && ![g_aniAlertisHidden]){
return;
}
[selfdimissAlertView];
g_aniAlert = [[UIAlertViewalloc]
initWithTitle:nilmessage:text
delegate:selfcancelButtonTitle:nil
otherButtonTitles: nil];
[g_aniAlertperformSelectorOnMainThread:@selector(show)withObject:nilwaitUntilDone:YES];
[NSTimerscheduledTimerWithTimeInterval:1target:selfselector:@selector(dimissAlertView)userInfo:nilrepeats:NO];
}
+(void)dimissAlertView{
[g_aniAlertdismissWithClickedButtonIndex:0animated:YES];
g_aniAlert = nil;
}
+(void)ShowAlertWithStr:(NSString*)text stayTime:(int)stayTime{
if(g_aniAlert!=nil && ![g_aniAlertisHidden]){
return;
}
[selfdimissAlertView];
g_aniAlert = [[UIAlertViewalloc]
initWithTitle:nilmessage:text
delegate:selfcancelButtonTitle:nil
otherButtonTitles: nil];
[g_aniAlertperformSelectorOnMainThread:@selector(show)withObject:nilwaitUntilDone:YES];
[NSTimerscheduledTimerWithTimeInterval:stayTimetarget:selfselector:@selector(dimissAlertView)userInfo:nilrepeats:NO];
}
+(void)ShowTextLoading:(NSString *)text
{
[selfdimissAlertView];
g_aniAlert = [[UIAlertViewalloc]
initWithTitle:nilmessage:text
delegate:selfcancelButtonTitle:nil
otherButtonTitles: nil];
[g_aniAlertperformSelectorOnMainThread:@selector(show)withObject:nilwaitUntilDone:YES];
}
@end
EIsGone = -15, //状态已改变
EBound = -16,//帐号已绑定其它设备
};
@interface UIAnimationTool : NSObject
+(void)ShowActivityIndicator:(UIView*)view at:(CGPoint)pos;
+(void)ShowActivityIndicator:(UIView*)view;
+(void)DisimissActivityIndicator;
+(void)ShowAlert:(NSString*) text;
+(void)ShowError:(int)Result;
+(void)ShowTextLoading:(NSString*)text;
+(void)dimissAlertView;
+(void)ShowAlertWithStr:(NSString*)text stayTime:(int)stayTime;
@end