1332 lines
42 KiB
Objective-C
Executable File
1332 lines
42 KiB
Objective-C
Executable File
//
|
||
// FuncPublic.m
|
||
// MaiTian
|
||
//
|
||
// Created by 谌 安 on 13-3-1.
|
||
// Copyright (c) 2013年 MaiTian. All rights reserved.
|
||
//
|
||
|
||
#import "FuncPublic.h"
|
||
#import "SGDefineInfo.h"
|
||
#import "AppDelegate.h"
|
||
#import "RootVC.h"
|
||
#import <CommonCrypto/CommonDigest.h>
|
||
#import "SBJSON.h"
|
||
#import <AudioToolbox/AudioToolbox.h>
|
||
#import <CoreTelephony/CTCall.h>
|
||
#import <CoreTelephony/CTCallCenter.h>
|
||
#import <CoreTelephony/CTCarrier.h>
|
||
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
|
||
#import <AVFoundation/AVFoundation.h>
|
||
FuncPublic * _funcPublic = nil;
|
||
@implementation FuncPublic
|
||
@synthesize spin;
|
||
@synthesize _NavigationArray;
|
||
@synthesize _CurrentShowNavigationIndex;
|
||
@synthesize _CurrentShow;
|
||
@synthesize _IsHomeEnter,flag;
|
||
@synthesize currentVC=currentVC_;
|
||
+(FuncPublic*)SharedFuncPublic
|
||
{
|
||
if( _funcPublic == nil )
|
||
{
|
||
_funcPublic = [[FuncPublic alloc] init];
|
||
_funcPublic._IsHomeEnter = YES;
|
||
_funcPublic.flag=YES;
|
||
}
|
||
return _funcPublic;
|
||
}
|
||
#pragma mark 打开及关闭风火轮
|
||
-(void)StartActivityAnimation:(UIViewController*)target
|
||
{
|
||
if( self.spin != nil )
|
||
{
|
||
[self.spin removeFromSuperview];
|
||
self.spin = nil;
|
||
}
|
||
spin=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
|
||
spin.color=[UIColor darkGrayColor];
|
||
spin.center=CGPointMake(DEVW/2, DEVH/2);
|
||
[target.view addSubview:spin];
|
||
[target.view bringSubviewToFront:self.spin];
|
||
[self.spin startAnimating];
|
||
}
|
||
-(void)StopActivityAnimation
|
||
{
|
||
[self.spin stopAnimating];
|
||
}
|
||
#pragma mark 打开及关闭风火轮 end------------
|
||
|
||
|
||
/*
|
||
*获得机型宽高
|
||
*/
|
||
+(CGRect)GetSceneRect
|
||
{
|
||
|
||
|
||
return [[UIScreen mainScreen] bounds];
|
||
}
|
||
/*
|
||
*将控件添加到windows上 控件的x坐标需要设定为-100
|
||
*view:需要添加到windows上面。显示在最上面的view
|
||
*/
|
||
+(void)ViewAddToWindows:(UIView*)view
|
||
{
|
||
|
||
UIWindow* window = [UIApplication sharedApplication].keyWindow;
|
||
if (!window) {
|
||
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
|
||
}
|
||
|
||
view.transform = CGAffineTransformScale([FuncPublic transformForOrientation], 0.001, 0.001);
|
||
[UIView beginAnimations:nil context:nil];
|
||
[UIView setAnimationDuration:1.5];
|
||
//[UIView setAnimationDelegate:self];
|
||
// [UIView setAnimationDidStopSelector:@selector(bounce1AnimationStopped)];
|
||
view.transform = CGAffineTransformScale([FuncPublic transformForOrientation], 1, 1);
|
||
[UIView commitAnimations];
|
||
//view.frame = CGRectMake(-100, 0, [FuncPublic GetSceneRect].size.width, [FuncPublic GetSceneRect].size.height);
|
||
[window addSubview:view];
|
||
}
|
||
+ (CGAffineTransform)transformForOrientation {
|
||
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
|
||
if (orientation == UIInterfaceOrientationLandscapeLeft) {
|
||
return CGAffineTransformMakeRotation(M_PI*1.5);
|
||
} else if (orientation == UIInterfaceOrientationLandscapeRight) {
|
||
return CGAffineTransformMakeRotation(M_PI/2);
|
||
} else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
|
||
return CGAffineTransformMakeRotation(-M_PI);
|
||
} else {
|
||
return CGAffineTransformIdentity;
|
||
}
|
||
}
|
||
#pragma mark 实例屏保 end----------
|
||
/*
|
||
*保存default信息
|
||
*srt:需保存的文字
|
||
*key:关键字
|
||
*/
|
||
+(void)SaveDefaultInfo:(id)str Key:(NSString*)_key
|
||
{
|
||
//+(NSString *)IsNull:(NSDictionary *)string Key:(NSString *)key;
|
||
|
||
// NSMutableDictionary *str_=[[NSMutableDictionary alloc]init];
|
||
NSUserDefaults *standardUserDefault = [NSUserDefaults standardUserDefaults];
|
||
/* need change
|
||
NSArray *keys=[str allKeys];
|
||
for (int i=0; i<[keys count]; i++) {
|
||
NSString* value = [self IsNull:str Key: [keys objectAtIndex:i]];
|
||
|
||
[str_ setObject:value forKey:[keys objectAtIndex:i]];
|
||
}
|
||
*/
|
||
[standardUserDefault setValue:str forKey:_key];
|
||
|
||
[standardUserDefault synchronize];
|
||
}
|
||
/*
|
||
*获得保存default信息
|
||
*key:关键字
|
||
*/
|
||
+(id)GetDefaultInfo:(NSString*)_key
|
||
{
|
||
id temp = [[NSUserDefaults standardUserDefaults] objectForKey:_key];
|
||
if( temp == nil )
|
||
{
|
||
return nil;
|
||
}
|
||
return temp;
|
||
}
|
||
/*
|
||
* str:需显示的信息
|
||
*/
|
||
+(void)ShowAlert:(NSString*)str
|
||
{
|
||
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"" message:str delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil] ;
|
||
[alert show];
|
||
}
|
||
/*
|
||
* str:需显示的信息 不重复
|
||
*/
|
||
+(void)ShowAlert:(NSString*)str title:(NSString *)title_ viewController:(UIViewController *)controller
|
||
{
|
||
if ([title_ isEqualToString:@"网络不可用"]||[str isEqualToString:@"没有数据!"]) {
|
||
|
||
|
||
if (!_funcPublic.flag) {
|
||
[[FuncPublic SharedFuncPublic]performSelector:@selector(OnceOk) withObject:nil afterDelay:30.f];
|
||
return;
|
||
}
|
||
_funcPublic.flag=NO;
|
||
}
|
||
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:title_ message:str delegate:controller cancelButtonTitle:@"确定" otherButtonTitles:nil];
|
||
[alert show];
|
||
|
||
}
|
||
-(void)OnceOk
|
||
{
|
||
_funcPublic.flag=YES;
|
||
}
|
||
/*
|
||
* _path = 图片路径
|
||
*/
|
||
+(NSString*)GetNewPhotoUrl:(NSString*)_path
|
||
{//edit an.chen
|
||
return [NSString stringWithFormat:@"%@/%@",SERVERSUB,_path];
|
||
}
|
||
/*
|
||
* name:文件名
|
||
* ext:后缀
|
||
*/
|
||
+(UIImage*)CreatedImageFromFile:(NSString *)name ofType:(NSString *)ext
|
||
{
|
||
//return [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:name ofType:ext]];
|
||
return [UIImage imageNamed:[NSString stringWithFormat:@"%@.%@",name,ext]];
|
||
}
|
||
|
||
/*
|
||
* 通过iphone的坐标得到 与误差坐标,得到 二个值
|
||
* IphoneRect:最初坐标
|
||
* num:误差值
|
||
* _kind: 1:X变 2:y变 3:w变 4: h变 5:x w 变 6: y h 变
|
||
*/
|
||
+(CGRect)Iphone5OrIphone4:(CGRect)IphoneRect Num:(float)_num Kind:(int)_kind
|
||
{
|
||
if( IS_IPHONE_5 )
|
||
{
|
||
return IphoneRect;
|
||
}
|
||
CGRect tempRect = CGRectZero;
|
||
switch (_kind) {
|
||
case 1:
|
||
tempRect = CGRectMake(IphoneRect.origin.x + _num, IphoneRect.origin.y,
|
||
IphoneRect.size.width, IphoneRect.size.height);
|
||
break;
|
||
case 2:
|
||
tempRect = CGRectMake(IphoneRect.origin.x , IphoneRect.origin.y+ _num,
|
||
IphoneRect.size.width, IphoneRect.size.height);
|
||
break;
|
||
case 3:
|
||
tempRect = CGRectMake(IphoneRect.origin.x, IphoneRect.origin.y,
|
||
IphoneRect.size.width+ _num, IphoneRect.size.height);
|
||
break;
|
||
case 4:
|
||
tempRect = CGRectMake(IphoneRect.origin.x, IphoneRect.origin.y,
|
||
IphoneRect.size.width, IphoneRect.size.height + _num);
|
||
break;
|
||
case 5:
|
||
tempRect = CGRectMake(IphoneRect.origin.x + _num, IphoneRect.origin.y,
|
||
IphoneRect.size.width + _num, IphoneRect.size.height);
|
||
break;
|
||
case 6:
|
||
tempRect = CGRectMake(IphoneRect.origin.x, IphoneRect.origin.y + _num,
|
||
IphoneRect.size.width, IphoneRect.size.height + _num);
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return tempRect;
|
||
}
|
||
|
||
/*
|
||
*通过尺寸获得size
|
||
* IphoneSize:最初坐标
|
||
* num:误差值
|
||
* _kind: 1:w变 2:h变
|
||
*/
|
||
+(CGSize)SizeByIphone:(CGSize)IphoneSize Num:(float)_num Kind:(int)_kind
|
||
{
|
||
if( IS_IPHONE_5 )
|
||
{
|
||
return IphoneSize;
|
||
}
|
||
CGSize tempSize = CGSizeZero;
|
||
switch (_kind) {
|
||
case 1:
|
||
{
|
||
tempSize = CGSizeMake(IphoneSize.width+_num, IphoneSize.height);
|
||
}
|
||
break;
|
||
case 2:
|
||
{
|
||
tempSize = CGSizeMake(IphoneSize.width, IphoneSize.height+_num);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return tempSize;
|
||
}
|
||
|
||
/*
|
||
* 实例image
|
||
*FileNmae:图片文件名
|
||
*ect:图片后缀名
|
||
*_rect:位置
|
||
*target:父类
|
||
*_index:tag
|
||
*/
|
||
+(UIImageView*)InstanceImageView:(NSString*)FileName FileName5:(NSString*)FileName5 Ect:(NSString*)ect RECT:(CGRect)_rect RECT5:(CGRect)_rect5 Target:(id)target TAG:(int)_index
|
||
{
|
||
UIImageView* view = [[UIImageView alloc] init];
|
||
|
||
if( IS_IPHONE_5 )
|
||
{
|
||
if( [FileName5 isEqualToString:@""] )
|
||
{
|
||
view.image = [FuncPublic CreatedImageFromFile:FileName ofType:ect];
|
||
}
|
||
else
|
||
view.image = [FuncPublic CreatedImageFromFile:FileName5 ofType:ect];
|
||
view.frame = _rect5;
|
||
}
|
||
else
|
||
{
|
||
if( [FileName isEqualToString:@""] )
|
||
{
|
||
view.image = [FuncPublic CreatedImageFromFile:FileName5 ofType:ect];
|
||
}
|
||
else
|
||
view.image = [FuncPublic CreatedImageFromFile:FileName ofType:ect];
|
||
view.frame = _rect;
|
||
}
|
||
view.tag = _index;
|
||
[(UIView*)target addSubview:view];
|
||
return view;
|
||
}
|
||
|
||
/*
|
||
* 攻能:图片等比例缩放,上下左右留白
|
||
* size:缩放的width,height
|
||
* _pimage:需要改变的图片
|
||
*/
|
||
+(UIImage*)scaleToSize:(CGSize)size ParentImage:(UIImage*)_PImage
|
||
{
|
||
CGFloat width = CGImageGetWidth(_PImage.CGImage);
|
||
CGFloat height = CGImageGetHeight(_PImage.CGImage);
|
||
|
||
float verticalRadio = size.height*1.0/height;
|
||
float horizontalRadio = size.width*1.0/width;
|
||
|
||
float radio = 1;
|
||
if(verticalRadio>1 && horizontalRadio>1)
|
||
{
|
||
radio = verticalRadio > horizontalRadio ? horizontalRadio : verticalRadio;
|
||
}
|
||
else
|
||
{
|
||
radio = verticalRadio < horizontalRadio ? verticalRadio : horizontalRadio;
|
||
}
|
||
|
||
width = width*radio;
|
||
height = height*radio;
|
||
|
||
int xPos = (size.width - width)/2;
|
||
int yPos = (size.height-height)/2;
|
||
|
||
// 创建一个bitmap的context
|
||
// 并把它设置成为当前正在使用的context
|
||
UIGraphicsBeginImageContext(size);
|
||
|
||
// 绘制改变大小的图片
|
||
[_PImage drawInRect:CGRectMake(xPos, yPos, width, height)];
|
||
|
||
// 从当前context中创建一个改变大小后的图片
|
||
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
|
||
|
||
// 使当前的context出堆栈
|
||
UIGraphicsEndImageContext();
|
||
|
||
// 返回新的改变大小后的图片
|
||
return scaledImage;
|
||
}
|
||
/*
|
||
*FileNmae:正常状态按键文件名
|
||
*ect:正常状态按键后缀名
|
||
*
|
||
*FileName2:按下状态文件名
|
||
*ect2:按下状态后缀名
|
||
*AddView:需要添加到的view,(有时可能直接需要view,所以增加了vc,用来做delegate)
|
||
*ViewController:用于做button delegate
|
||
*_rect:位置
|
||
*_sel:方法
|
||
*_Kind:1=setBackgroundImage 2= setImage
|
||
*_index:tag
|
||
*/
|
||
+(UIButton*)InstanceButton:(NSString*)FileName Ect:(NSString*)ect FileName2:(NSString*)FileName2 Ect2:(NSString*)ect2 RECT:(CGRect)_rect RECT5:(CGRect)_rect5 AddView:(UIView*)view ViewController:(UIViewController*)VC SEL_:(SEL)_sel Kind:(int)_Kind TAG:(int)_index
|
||
{
|
||
|
||
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
if( IS_IPHONE_5 )
|
||
{
|
||
button.frame = _rect5;
|
||
}
|
||
else
|
||
{
|
||
button.frame = _rect;
|
||
}
|
||
//button.backgroundColor = [UIColor redColor];
|
||
if( _Kind == 1 )
|
||
{
|
||
if(![FileName isEqualToString:@""])
|
||
{
|
||
[button setBackgroundImage:[FuncPublic CreatedImageFromFile:FileName ofType:ect] forState:UIControlStateNormal];
|
||
}
|
||
if(![FileName2 isEqualToString:@""])
|
||
{
|
||
[button setBackgroundImage:[FuncPublic CreatedImageFromFile:FileName2 ofType:ect2] forState:UIControlStateHighlighted];
|
||
}
|
||
}
|
||
else if(_Kind == 2 )
|
||
{
|
||
UIImage *image=[FuncPublic CreatedImageFromFile:FileName ofType:ect];
|
||
CGSize frame=button.frame.size;
|
||
if(frame.height<image.size.height/2)
|
||
{
|
||
[button setImageEdgeInsets:UIEdgeInsetsMake((frame.height-image.size.height/2)/2, (frame.width-image.size.width/2)/2, (frame.height-image.size.height/2)/2, (frame.width-image.size.width/2)/2)];
|
||
}else
|
||
{
|
||
[button setImageEdgeInsets:UIEdgeInsetsMake((frame.height-image.size.height/4)/2, (frame.width-image.size.width/4)/2, (frame.height-image.size.height/4)/2, (frame.width-image.size.width/4)/2)];
|
||
}
|
||
if(![FileName isEqualToString:@""])
|
||
{
|
||
[button setImage:[FuncPublic CreatedImageFromFile:FileName ofType:ect] forState:UIControlStateNormal];
|
||
|
||
}
|
||
if(![FileName2 isEqualToString:@""])
|
||
{
|
||
[button setImage:[FuncPublic CreatedImageFromFile:FileName2 ofType:ect2] forState:UIControlStateHighlighted];
|
||
}
|
||
}
|
||
[button addTarget:VC action:_sel forControlEvents:UIControlEventTouchUpInside];
|
||
//[button setExclusiveTouch:YES];//防止多按
|
||
button.tag = _index;
|
||
[view addSubview:button];
|
||
return button;
|
||
}
|
||
/*
|
||
*实例label
|
||
*_info:lable信息
|
||
*_rect:位置
|
||
*name:字体名字,没有则,不需要特别设置
|
||
*_red:字体红色
|
||
*green:字体绿色
|
||
*blue:字体蓝色
|
||
*_fontsize:字体大小
|
||
*target:parent类
|
||
*Lines:几行
|
||
*_index:tag
|
||
*/
|
||
+(UILabel*)InstanceLabel:(NSString*)_Info RECT:(CGRect)_rect RECT5:(CGRect)_rect5 FontName:(NSString*)Name Red:(CGFloat)_red green:(CGFloat)green blue:(CGFloat)blue FontSize:(int)_FontSize Target:(id)target Lines:(int)_lines TAG:(int)_index Ailgnment:(int)_ailgnment//1:中,2:左,3:右
|
||
{
|
||
UILabel* label = [[UILabel alloc] initWithFrame:_rect];
|
||
if( IS_IPHONE_5 )
|
||
{
|
||
label.frame = _rect5;
|
||
}
|
||
else
|
||
{
|
||
label.frame = _rect;
|
||
}
|
||
label.text = _Info;
|
||
switch (_ailgnment) {
|
||
case 1:
|
||
label.textAlignment = NSTextAlignmentCenter;
|
||
break;
|
||
case 2:
|
||
label.textAlignment = NSTextAlignmentLeft;
|
||
break;
|
||
case 3:
|
||
label.textAlignment = NSTextAlignmentRight;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
label.backgroundColor = [UIColor clearColor];
|
||
label.numberOfLines = 0;// _lines;
|
||
[FuncPublic ChangeLable:&label FontName:Name Red:_red green:green blue:blue FontSize:_FontSize];
|
||
label.tag = _index;
|
||
[(UIView*)target addSubview:label];
|
||
return label;
|
||
}
|
||
/*
|
||
* 将指定控件移到当前最上层
|
||
* _view:需要改变的view
|
||
* _index:需要移动到最上层的索引
|
||
*/
|
||
+(void)MoveUIToTop:(UIView*)_view Index:(int)_index
|
||
{
|
||
for(UIView* item in _view.subviews )
|
||
{
|
||
if( _index == item.tag )
|
||
{
|
||
[_view bringSubviewToFront:item];
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
/*
|
||
* label:需要改变的label地址
|
||
* name:字体名字
|
||
* _red:红色值
|
||
* green:绿色值
|
||
* blue: 蓝色值
|
||
* _fontsize:字体大小
|
||
*/
|
||
+(void)ChangeLable:(UILabel**)label FontName:(NSString*)Name Red:(CGFloat)_red green:(CGFloat)green blue:(CGFloat)blue FontSize:(int)_FontSize
|
||
{
|
||
//edit an.chen
|
||
if( [Name isEqualToString:@""] )
|
||
{
|
||
Name = @"Thonburi";
|
||
}
|
||
(*label).font = [UIFont fontWithName:Name size:_FontSize];
|
||
(*label).textColor = [UIColor colorWithRed:_red/255 green:green/255 blue:blue/255 alpha:1];
|
||
}
|
||
|
||
/*
|
||
* 动画移位
|
||
* _rect:需要移动到的位置
|
||
* _view:需要移动的视图
|
||
* _duration:动画时间
|
||
* _str:动画名
|
||
* sel:移动完成后返回的方法
|
||
*/
|
||
+(void)Translation:(CGRect)_rect Image:(UIView*)_view Duration:(float)_Duration Str:(NSString*)_str Select:(SEL)sel
|
||
tager:(id)_tager
|
||
{
|
||
[UIView beginAnimations:_str context:NULL];
|
||
// //移动时间2秒
|
||
[UIView setAnimationDuration:_Duration];
|
||
//
|
||
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
|
||
//
|
||
// //图片持续移动
|
||
[UIView setAnimationBeginsFromCurrentState:YES];
|
||
[UIView setAnimationDidStopSelector:sel];
|
||
[UIView setAnimationDelegate:_tager];
|
||
// //重新定义图片的位置和尺寸,位置
|
||
_view.frame = _rect;
|
||
// //完成动画移动
|
||
[UIView commitAnimations];
|
||
}
|
||
|
||
/*
|
||
*获得navigationarray的实例
|
||
*/
|
||
+(NSMutableArray*)NavigationArray
|
||
{
|
||
if( [FuncPublic SharedFuncPublic]._NavigationArray == nil )
|
||
{
|
||
[FuncPublic SharedFuncPublic]._NavigationArray = [[NSMutableArray alloc] init];
|
||
}
|
||
return [FuncPublic SharedFuncPublic]._NavigationArray;
|
||
}
|
||
/*
|
||
*通过name实例类,并添加navigation
|
||
*Name:类名
|
||
*_nav:保存navigation
|
||
*_pvc:父类
|
||
*/
|
||
+(void)InstanceVC:(NSString*)Name ParentVC:(UIViewController*)_pVC
|
||
{
|
||
id temp = [[NSClassFromString(Name) alloc] initWithNibName:Name bundle:nil];
|
||
// [(UIViewController*)temp viewWillAppear:NO];
|
||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] initWithCapacity:2];
|
||
[dict setObject:temp forKey:@"Nav"];
|
||
[dict setObject:Name forKey:@"ClassName"];
|
||
[[FuncPublic NavigationArray] addObject:dict];
|
||
|
||
}
|
||
-(void)setCurrentVC:(UIViewController *)currentVC
|
||
{
|
||
if (currentVC_==nil) {
|
||
currentVC_=currentVC ;
|
||
// [currentVC retain];
|
||
}else
|
||
{
|
||
//[currentVC_ release];
|
||
currentVC_=currentVC;
|
||
// [currentVC_ retain];
|
||
}
|
||
|
||
}
|
||
+(void)TransitionView:(int)_index
|
||
{
|
||
if( _index == [FuncPublic SharedFuncPublic]._CurrentShowNavigationIndex )return;
|
||
UIViewController *vcOld;
|
||
UIViewController *vcNew;
|
||
[FuncPublic SharedFuncPublic].currentVC=vcNew;
|
||
if( [FuncPublic SharedFuncPublic]._CurrentShowNavigationIndex != 0 )
|
||
{
|
||
NSMutableDictionary* dict = [[FuncPublic SharedFuncPublic]._NavigationArray objectAtIndex:[FuncPublic SharedFuncPublic]._CurrentShowNavigationIndex-1];
|
||
vcOld = [dict objectForKey:@"Nav"];
|
||
vcOld.view.hidden = YES;
|
||
[vcOld viewDidDisappear:YES];
|
||
[vcOld.navigationController popToRootViewControllerAnimated:NO];
|
||
|
||
}
|
||
NSMutableDictionary* dict = [[FuncPublic SharedFuncPublic]._NavigationArray objectAtIndex:_index-1];
|
||
|
||
vcNew = [dict objectForKey:@"Nav"];
|
||
//[vcNew viewWillAppear:YES];
|
||
vcNew.view.hidden = NO;
|
||
[vcNew.navigationController popToRootViewControllerAnimated:NO];
|
||
AppDelegate* delegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
|
||
[FuncPublic SharedFuncPublic]._CurrentShowNavigationIndex = _index;
|
||
//[FuncPublic PushAnimation:(UIViewController *)delegate.root InsertVC:vcNew];
|
||
[FuncPublic SharedFuncPublic].currentVC=vcNew;
|
||
[delegate.root.navigationController pushViewController:vcNew animated:NO];
|
||
[FuncPublic SharedFuncPublic]._IsHomeEnter = NO;
|
||
}
|
||
//edit an.chen
|
||
/*
|
||
*移除动画
|
||
*/
|
||
+(void)RemoveWindowsAnimation
|
||
{
|
||
UIWindow* window = [UIApplication sharedApplication].keyWindow;
|
||
if (!window) {
|
||
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
|
||
}
|
||
[window.layer removeAnimationForKey:@"aa"];
|
||
}
|
||
/*
|
||
*增加push动画效果
|
||
*ParentVC:父类vc
|
||
*InsertVC:需要显示的vc
|
||
*/
|
||
+(void)PushAnimation:(UIViewController *)ParentVC InsertVC:(UIViewController*)InsertVC
|
||
{
|
||
[FuncPublic SharedFuncPublic].currentVC=InsertVC;
|
||
|
||
[ParentVC.navigationController pushViewController:InsertVC animated:YES];
|
||
|
||
}
|
||
|
||
/*
|
||
*增加push动画效果
|
||
*ParentVC:父类vc
|
||
*/
|
||
+(void)PopAnimation:(UIViewController*)ParentVC
|
||
{
|
||
|
||
|
||
[ParentVC.navigationController popViewControllerAnimated:YES];
|
||
}
|
||
/*
|
||
*增加pop动画效果 通过跳转的len
|
||
*ParentVC:父类vc
|
||
*/
|
||
+(void)PopAnimation:(UIViewController*)ParentVC Len:(int)len
|
||
{
|
||
NSInteger Count = [ParentVC.navigationController.viewControllers count]-1;
|
||
UIViewController* view = [ParentVC.navigationController.viewControllers objectAtIndex:Count-len];
|
||
[ParentVC.navigationController popToViewController:view animated:YES];
|
||
}
|
||
|
||
|
||
/*
|
||
*通过毫秒获得日期
|
||
*/
|
||
+(NSString*)StringTimeToDate:(NSString*)str
|
||
{
|
||
NSString* tem = str;//Date(1363190400000+0800)
|
||
NSArray* array = [tem componentsSeparatedByString:@"("];
|
||
if( array > 0 )
|
||
{
|
||
NSString* string = [array objectAtIndex:1];
|
||
NSArray* array2 = [string componentsSeparatedByString:@")"];
|
||
if( [array2 count] <= 1 )
|
||
{
|
||
return @"";
|
||
}
|
||
else if( [array2 count] > 1 )
|
||
{
|
||
NSString* NewStr = [array2 objectAtIndex:0];
|
||
NSTimeInterval Time = [NewStr longLongValue];
|
||
NSDate *date = [NSDate dateWithTimeIntervalSince1970:Time/1000];
|
||
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
|
||
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
|
||
NSString *regStr = [dateFormatter stringFromDate:date];
|
||
return regStr;
|
||
}
|
||
|
||
}
|
||
return @"";
|
||
}
|
||
/*
|
||
*通过毫秒获得日期
|
||
*/
|
||
+(NSDate*)StringTimeToRetrunDate:(NSString*)str
|
||
{
|
||
NSString* tem = str;//Date(1363190400000+0800)
|
||
NSArray* array = [tem componentsSeparatedByString:@"("];
|
||
if( array > 0 )
|
||
{
|
||
NSString* string = [array objectAtIndex:1];
|
||
NSArray* array2 = [string componentsSeparatedByString:@")"];
|
||
if( [array2 count] <= 1 )
|
||
{
|
||
return nil;
|
||
}
|
||
else if( [array2 count] > 1 )
|
||
{
|
||
NSString* NewStr = [array2 objectAtIndex:0];
|
||
NSTimeInterval Time = [NewStr longLongValue];
|
||
NSDate *date = [NSDate dateWithTimeIntervalSince1970:Time/1000];
|
||
return date;
|
||
}
|
||
|
||
}
|
||
return nil;
|
||
}
|
||
+(NSString *) urlEncoderString:(NSString *)str
|
||
{
|
||
NSString *result = (NSString *) CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,
|
||
(CFStringRef)str,
|
||
NULL,
|
||
(CFStringRef)@";/?:@&=$+{}<>,",
|
||
kCFStringEncodingUTF8));
|
||
/* 上面意思就是把 str转化为网络上可以传输的标准格式
|
||
CFStringRef就是一个C语言的NSString类
|
||
CF = CoreFoundation
|
||
(CFStringRef)@";/?:@&=$+{}<>," 表示这些不用转化
|
||
*/
|
||
return result ;
|
||
}
|
||
|
||
/*
|
||
dict: 字典文件
|
||
key: 关键字
|
||
kind: 种类 1:string 2:NSMutableArray 3:NSMutableDictionary
|
||
*/
|
||
+(id)tryObjectForKey:(NSMutableDictionary*)dict Key:(NSString*)key Kind:(int)kind
|
||
{
|
||
id temp = nil;
|
||
switch (kind) {
|
||
case 1:
|
||
temp = @"";
|
||
break;
|
||
case 2:
|
||
temp = [[NSMutableArray alloc] init];
|
||
break;
|
||
case 3:
|
||
temp = [[NSMutableDictionary alloc] init];
|
||
break;
|
||
default:
|
||
temp = @"";
|
||
break;
|
||
}
|
||
|
||
@try {
|
||
temp = [dict objectForKey:key];
|
||
}
|
||
@catch (NSException *exception) {
|
||
|
||
}
|
||
return temp;
|
||
}
|
||
+(NSString*)ConvertFloat:(float)Num
|
||
{
|
||
NSString* tempString = @"";
|
||
if( Num > 9999.0f && Num < 99999999.0f)
|
||
{
|
||
NSString* TEMP = [NSString stringWithFormat:@"%.2f",((float)Num)/10000.0f];
|
||
TEMP = [FuncPublic setDivMarkup:TEMP];
|
||
tempString = [NSString stringWithFormat:@"%@万",TEMP];
|
||
}
|
||
else if( Num > 99999999.0f )
|
||
{
|
||
NSString* TEMP = [NSString stringWithFormat:@"%.2f",((float)Num)/100000000.0f];
|
||
TEMP = [FuncPublic setDivMarkup:TEMP];
|
||
tempString = [NSString stringWithFormat:@"%@亿",TEMP];
|
||
}
|
||
else
|
||
{
|
||
tempString = [NSString stringWithFormat:@"%.0f元",Num];
|
||
}
|
||
return tempString;
|
||
}
|
||
+ (NSString *)setDivMarkup:(NSString *)markup
|
||
{
|
||
NSString *regexToReplaceWidth = @"^(\\d+?\\.\\d*?)0+$";
|
||
|
||
NSError *error = NULL;
|
||
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexToReplaceWidth
|
||
options:NSRegularExpressionCaseInsensitive
|
||
error:&error];
|
||
NSString* temp2 = [regex stringByReplacingMatchesInString:markup
|
||
options:0
|
||
range:NSMakeRange(0, markup.length)
|
||
withTemplate:@"$1"];
|
||
|
||
NSString *regexToReplaceWidth1 = @"(\\d+)\\.$";
|
||
NSRegularExpression *regex1 = [NSRegularExpression regularExpressionWithPattern:regexToReplaceWidth1
|
||
options:NSRegularExpressionCaseInsensitive
|
||
error:&error];
|
||
return [regex1 stringByReplacingMatchesInString:temp2
|
||
options:0
|
||
range:NSMakeRange(0, temp2.length)
|
||
withTemplate:@"$1"];
|
||
}
|
||
|
||
/*
|
||
* 计算二个星期索引相差多少天
|
||
* oneWeekly:开始的星期索引
|
||
* twoweekly:结束的星期索引
|
||
*/
|
||
+(int)TwoWeeklyDiffer:(int)oneWeekly TwoWeekly:(int)twoWeekly
|
||
{
|
||
if( oneWeekly == twoWeekly )
|
||
return 7;
|
||
else if( oneWeekly > twoWeekly )
|
||
{
|
||
return (( twoWeekly + 7 ) - oneWeekly);
|
||
}
|
||
else if( oneWeekly < twoWeekly )
|
||
{
|
||
return twoWeekly - oneWeekly;
|
||
}
|
||
return 7;
|
||
}
|
||
/*
|
||
* 实例通知
|
||
* name: 闹钟显示名字
|
||
* _action:是否动作
|
||
* _date: 响铃日期
|
||
*/
|
||
+(void)InstanceLocalNotification:(NSString*)name HasAction:(BOOL)_Action Date:(NSDate*)date{
|
||
UIApplication * app = [UIApplication sharedApplication];
|
||
UILocalNotification* alarm = [[UILocalNotification alloc] init] ;
|
||
if(!alarm)//本地不支持
|
||
{
|
||
return;
|
||
}
|
||
alarm.fireDate = date;
|
||
alarm.repeatInterval = kCFCalendarUnitEra;
|
||
alarm.timeZone = [NSTimeZone defaultTimeZone];
|
||
|
||
alarm.alertBody = name;
|
||
|
||
alarm.alertAction = @"OK";
|
||
|
||
alarm.hasAction=_Action;
|
||
|
||
[app scheduleLocalNotification:alarm];
|
||
}
|
||
/*
|
||
滑屏手势
|
||
_view:需要移动的视图
|
||
vc_:控制视图
|
||
sel:移动完成后返回的方法
|
||
status:状态 0:表示右 气态左
|
||
*/
|
||
-(void)UISwipeGestrue_Direction:(UIView *)view_ controllerview:(UIViewController *)vc_ Direction:(int)status SEL:(SEL)_sel {
|
||
|
||
UISwipeGestureRecognizer *recognizer;
|
||
|
||
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:vc_ action:_sel];
|
||
if (status==0) {
|
||
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
|
||
}else
|
||
{
|
||
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
|
||
}
|
||
|
||
[view_ addGestureRecognizer:recognizer];
|
||
|
||
|
||
}
|
||
/*
|
||
*获得星期所代表的数字
|
||
*/
|
||
+(int)WeekInt:(NSString*)str
|
||
{
|
||
if( [str isEqualToString:@"星期一"] || [str isEqualToString:@"Monday"] )
|
||
{
|
||
return 1;
|
||
}
|
||
else if( [str isEqualToString:@"星期二"] || [str isEqualToString:@"Tuesday"] )
|
||
{
|
||
return 2;
|
||
}else if( [str isEqualToString:@"星期三"] || [str isEqualToString:@"Wednesday"] )
|
||
{
|
||
return 3;
|
||
}else if( [str isEqualToString:@"星期四"] || [str isEqualToString:@"Thursday"] )
|
||
{
|
||
return 4;
|
||
}else if( [str isEqualToString:@"星期五"] || [str isEqualToString:@"Friday"] )
|
||
{
|
||
return 5;
|
||
}else if( [str isEqualToString:@"星期六"] || [str isEqualToString:@"Saturday"] )
|
||
{
|
||
return 6;
|
||
}else if( [str isEqualToString:@"星期日"] || [str isEqualToString:@"Sunday"] )
|
||
{
|
||
return 7;
|
||
}
|
||
return 7;
|
||
}
|
||
/*
|
||
IOS7坐标移位
|
||
*/
|
||
+(int)IosPosChange
|
||
{
|
||
if( IOS_VERSION >= 7.0f )
|
||
{
|
||
return 20;
|
||
}
|
||
return 0;
|
||
}
|
||
-(void)allok:(UIViewController *)controview
|
||
{
|
||
if (IS_IPHONE_7) {
|
||
NSArray *views=[controview.view subviews];
|
||
for (UIView *view in views) {
|
||
CGRect rect=view.frame;
|
||
rect.origin.y=rect.origin.y+20;
|
||
view.frame=rect;
|
||
}
|
||
}
|
||
}
|
||
/*
|
||
判断字符串是否为空
|
||
*/
|
||
+(NSString *)IsNull:(NSDictionary *)string Key:(NSString *)key;
|
||
{
|
||
if ( [string objectForKey:key]==[NSNull null]||[[string objectForKey:key] isEqualToString:@"null"]) {
|
||
return @"";
|
||
}else
|
||
{
|
||
return [string objectForKey:key];
|
||
}
|
||
}
|
||
//将16进制html颜色转成 UIColor
|
||
+ (UIColor *)getColorWithHexString:(NSString *)string
|
||
{
|
||
NSString *cString = [[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
|
||
|
||
// String should be 6 or 8 characters
|
||
if ([cString length] < 6) return [UIColor lightGrayColor];
|
||
|
||
// strip 0X if it appears
|
||
if ([cString hasPrefix:@"0X"]) cString = [cString substringFromIndex:2];
|
||
if ([cString hasPrefix:@"#"]) cString = [cString substringFromIndex:1];
|
||
if ([cString length] != 6) return [UIColor lightGrayColor];
|
||
// Separate into r, g, b substrings
|
||
NSRange range;
|
||
range.location = 0;
|
||
range.length = 2;
|
||
NSString *rString = [cString substringWithRange:range];
|
||
|
||
range.location = 2;
|
||
NSString *gString = [cString substringWithRange:range];
|
||
|
||
range.location = 4;
|
||
NSString *bString = [cString substringWithRange:range];
|
||
|
||
// Scan values
|
||
unsigned int r, g, b;
|
||
[[NSScanner scannerWithString:rString] scanHexInt:&r];
|
||
[[NSScanner scannerWithString:gString] scanHexInt:&g];
|
||
[[NSScanner scannerWithString:bString] scanHexInt:&b];
|
||
|
||
return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];
|
||
}
|
||
|
||
//判断是否是电子邮箱
|
||
+ (BOOL)isEmail:(NSString*)email
|
||
{
|
||
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
|
||
NSPredicate *emailPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
|
||
return [emailPre evaluateWithObject:email];
|
||
}
|
||
|
||
//判断是否是手机号码
|
||
+ (BOOL)isMobilePhone:(NSString *)mobilePhone
|
||
{
|
||
//手机号以13, 15,18开头,八个 \d 数字字符
|
||
NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
|
||
NSPredicate *phonePre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
|
||
|
||
return [phonePre evaluateWithObject:mobilePhone];
|
||
}
|
||
|
||
//判断是否是QQ号码
|
||
+ (BOOL)isQQ:(NSString *)qq
|
||
{
|
||
NSString *qqRegex = @"^\\d{5,12}$";
|
||
NSPredicate *qqPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",qqRegex];
|
||
|
||
return [qqPre evaluateWithObject:qq];
|
||
}
|
||
//获得设备信息
|
||
+ (NSMutableDictionary *)getDeviceInfo
|
||
{
|
||
NSMutableDictionary *dic=[[NSMutableDictionary alloc] init] ;
|
||
|
||
[dic setObject:[FuncPublic getDeviceIdentifier] forKey:@"DeviceIdentifier"];
|
||
[dic setObject:[[UIDevice currentDevice] name] forKey:@"DeviceDisplayName"];
|
||
[dic setObject:[[UIDevice currentDevice] systemName] forKey:@"DeviceSystemName"];
|
||
[dic setObject:[[UIDevice currentDevice] systemVersion] forKey:@"DeviceSystemVersion"];
|
||
|
||
return dic;
|
||
}
|
||
//获得设备唯一识别号
|
||
+ (NSString *)getDeviceIdentifier
|
||
{
|
||
|
||
return [FuncPublic getDeviceID];
|
||
|
||
}
|
||
//获得设备id
|
||
+ (NSString *)getDeviceID
|
||
{
|
||
return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
|
||
}
|
||
|
||
|
||
//利用正则表达式验证邮箱地址合法性
|
||
+(BOOL)isValidateEmail:(NSString *)email {
|
||
|
||
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
|
||
|
||
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
|
||
|
||
return [emailTest evaluateWithObject:email];
|
||
|
||
}
|
||
+(BOOL)validateMobile:(NSString* )mobile {
|
||
// //手机号以13, 15,18开头,八个 \d 数字字符
|
||
// NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
|
||
// NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
|
||
// NSLog(@"phoneTest is %@",phoneTest);
|
||
// return [phoneTest evaluateWithObject:mobile];
|
||
/**
|
||
* 手机号码
|
||
* 移动:134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
|
||
* 联通:130,131,132,152,155,156,185,186
|
||
* 电信:133,1349,153,180,189
|
||
*/
|
||
NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";
|
||
/**
|
||
10 * 中国移动:China Mobile
|
||
11 * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
|
||
12 */
|
||
NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";
|
||
/**
|
||
15 * 中国联通:China Unicom
|
||
16 * 130,131,132,152,155,156,185,186
|
||
17 */
|
||
NSString * CU = @"^1(3[0-2]|5[256]|8[56]|7[7])\\d{8}$";
|
||
/**
|
||
20 * 中国电信:China Telecom
|
||
21 * 133,1349,153,180,189 18开头
|
||
22 */
|
||
NSString * CT = @"^1((33|53|8[0,0-9])[0-9]|349)\\d{7}$";
|
||
/**
|
||
25 * 大陆地区固话及小灵通
|
||
26 * 区号:010,020,021,022,023,024,025,027,028,029
|
||
27 * 号码:七位或八位
|
||
28 */
|
||
// NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";
|
||
|
||
NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
|
||
NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
|
||
NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
|
||
NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
|
||
|
||
if (([regextestmobile evaluateWithObject:mobile] == YES)
|
||
|| ([regextestcm evaluateWithObject:mobile] == YES)
|
||
|| ([regextestct evaluateWithObject:mobile] == YES)
|
||
|| ([regextestcu evaluateWithObject:mobile] == YES))
|
||
{
|
||
return YES;
|
||
}
|
||
else
|
||
{
|
||
return NO;
|
||
}
|
||
}
|
||
/*
|
||
* 验证数据信息
|
||
*type_ 1,phone number 2,email 3,normal
|
||
*/
|
||
+(BOOL)Validate:(NSString *)info type:(int)type_ infotitle:(NSString *)title viewController:(UIViewController *)controller;
|
||
{
|
||
NSString *tip=@"";
|
||
BOOL bool_=YES;
|
||
if (info.length<1) {
|
||
tip=[NSString stringWithFormat:@"%@不能为空",title];
|
||
bool_=NO;
|
||
}else
|
||
{
|
||
if (type_==1) {
|
||
bool_=[self validateMobile:info];
|
||
if (!bool_) {
|
||
tip=@"手机格式不对";
|
||
}
|
||
}
|
||
if (type_==2) {
|
||
bool_=[self isValidateEmail:info];
|
||
if (!bool_) {
|
||
tip=@"邮件格式不对";
|
||
}
|
||
}
|
||
}
|
||
return bool_;
|
||
}
|
||
|
||
|
||
//获得密钥
|
||
+ (NSString *)getSecretKey
|
||
{
|
||
return @"ios2013ForLY";
|
||
}
|
||
//获得文件在沙盒中的路径,1:Document,2:Library\\Caches,3:App
|
||
+ (NSString *)getFilePath:(NSString *)fileName PathType:(int)type
|
||
{
|
||
NSString *filePath;
|
||
|
||
if(type==1)
|
||
{
|
||
filePath=[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:fileName];
|
||
}
|
||
else if(type==2)
|
||
{
|
||
filePath=[NSHomeDirectory() stringByAppendingFormat:@"/Library/Caches/%@",fileName];
|
||
}
|
||
else
|
||
{
|
||
filePath=[[[NSBundle mainBundle] bundlePath] stringByAppendingFormat:@"/%@",fileName];
|
||
}
|
||
|
||
return filePath;
|
||
}
|
||
//返回字符串为文件名的前缀或后缀
|
||
+ (NSString *)getStringItem:(NSString *)string WithType:(int)type
|
||
{
|
||
NSString *TheExtension=[string pathExtension];
|
||
if(type==0)
|
||
{
|
||
return [string substringWithRange:NSMakeRange(0, string.length-TheExtension.length-1)];
|
||
}
|
||
else
|
||
{
|
||
return TheExtension;
|
||
}
|
||
}
|
||
|
||
//产生用户充值Hash码
|
||
+ (NSString *)createUserGoldChargeHashByStoreID:(NSString *)storeID AndDeviceID:(NSString *)deviceID AndUserID:(NSString *)userID AndTransactionID:(NSString *)transactionID ChargePrice:(float )Price ChargeGold:(int) Gold
|
||
{
|
||
return [NSString stringWithFormat:@"%@%@%@%@%.2f%d%@",storeID,deviceID,userID,transactionID,Price,Gold,[FuncPublic getSecretKey]];
|
||
}
|
||
|
||
|
||
#pragma mark - 生成当前时间字符串
|
||
+ (NSString*)GetCurrentTimeString{
|
||
NSDateFormatter *dateformat = [[NSDateFormatter alloc]init];
|
||
[dateformat setDateFormat:@"yyyyMMddHHmmss"];
|
||
return [dateformat stringFromDate:[NSDate date]];
|
||
}
|
||
|
||
#pragma mark - 生成文件路径
|
||
+ (NSString*)GetPathByFileName:(NSString *)_fileName ofType:(NSString *)_type{
|
||
NSString *directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];;
|
||
NSString* fileDirectory = [[[directory stringByAppendingPathComponent:_fileName]
|
||
stringByAppendingPathExtension:_type]
|
||
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||
return fileDirectory;
|
||
}
|
||
+(int)ifauth
|
||
{
|
||
int flag;
|
||
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
|
||
switch (authStatus) {
|
||
case AVAuthorizationStatusNotDetermined:
|
||
//没有询问是否开启麦克风
|
||
flag = 1;
|
||
break;
|
||
case AVAuthorizationStatusRestricted:
|
||
//未授权,家长限制
|
||
flag = 0;
|
||
break;
|
||
case AVAuthorizationStatusDenied:
|
||
//玩家未授权
|
||
flag = 0;
|
||
break;
|
||
case AVAuthorizationStatusAuthorized:
|
||
//玩家授权
|
||
flag = 2;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return flag;
|
||
//[FuncPublic SaveDefaultInfo:[NSString stringWithFormat:@"%d",flag] Key:@"authStatus"];
|
||
}
|
||
+( UIImage *)getImageWithFullScreenshot
|
||
{
|
||
// Source (Under MIT License): https://github.com/shinydevelopment/SDScreenshotCapture/blob/master/SDScreenshotCapture/SDScreenshotCapture.m#L35
|
||
|
||
|
||
|
||
CGSize imageSize = CGSizeZero;
|
||
|
||
imageSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
|
||
|
||
UIGraphicsBeginImageContextWithOptions(imageSize, NO, [UIScreen mainScreen].scale);
|
||
CGContextRef context = UIGraphicsGetCurrentContext();
|
||
|
||
for (UIWindow *window in [[UIApplication sharedApplication] windows])
|
||
{
|
||
CGContextSaveGState(context);
|
||
CGContextTranslateCTM(context, window.center.x, window.center.y);
|
||
CGContextConcatCTM(context, window.transform);
|
||
CGContextTranslateCTM(context, -window.bounds.size.width * window.layer.anchorPoint.x, -window.bounds.size.height * window.layer.anchorPoint.y);
|
||
|
||
// Correct for the screen orientation
|
||
|
||
// CGContextRotateCTM(context, (CGFloat)M_PI);
|
||
// CGContextTranslateCTM(context, -imageSize.width, -imageSize.height);
|
||
|
||
|
||
|
||
if([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)])
|
||
[window drawViewHierarchyInRect:window.bounds afterScreenUpdates:NO];
|
||
else
|
||
[window.layer renderInContext:UIGraphicsGetCurrentContext()];
|
||
|
||
CGContextRestoreGState(context);
|
||
}
|
||
|
||
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
|
||
|
||
UIGraphicsEndImageContext();
|
||
|
||
return image;
|
||
}
|
||
|
||
//图片压缩到指定大小
|
||
+(UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize image:(UIImage *)sourceImage
|
||
{
|
||
|
||
UIImage *newImage = nil;
|
||
CGSize imageSize = sourceImage.size;
|
||
CGFloat width = imageSize.width;
|
||
CGFloat height = imageSize.height;
|
||
CGFloat targetWidth = targetSize.width;
|
||
CGFloat targetHeight = targetSize.height;
|
||
CGFloat scaleFactor = 0.0;
|
||
CGFloat scaledWidth = targetWidth;
|
||
CGFloat scaledHeight = targetHeight;
|
||
CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
|
||
|
||
if (CGSizeEqualToSize(imageSize, targetSize) == NO)
|
||
{
|
||
CGFloat widthFactor = targetWidth / width;
|
||
CGFloat heightFactor = targetHeight / height;
|
||
|
||
if (widthFactor > heightFactor)
|
||
scaleFactor = widthFactor; // scale to fit height
|
||
else
|
||
scaleFactor = heightFactor; // scale to fit width
|
||
scaledWidth= width * scaleFactor;
|
||
scaledHeight = height * scaleFactor;
|
||
|
||
// center the image
|
||
if (widthFactor > heightFactor)
|
||
{
|
||
thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
|
||
}
|
||
else if (widthFactor < heightFactor)
|
||
{
|
||
thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
|
||
}
|
||
}
|
||
|
||
UIGraphicsBeginImageContext(targetSize); // this will crop
|
||
|
||
CGRect thumbnailRect = CGRectZero;
|
||
thumbnailRect.origin = thumbnailPoint;
|
||
thumbnailRect.size.width= scaledWidth;
|
||
thumbnailRect.size.height = scaledHeight;
|
||
|
||
[sourceImage drawInRect:thumbnailRect];
|
||
|
||
newImage = UIGraphicsGetImageFromCurrentImageContext();
|
||
if(newImage == nil)
|
||
NSLog(@"could not scale image");
|
||
|
||
//pop the context to get back to the default
|
||
UIGraphicsEndImageContext();
|
||
return newImage;
|
||
}
|
||
//取得文件名
|
||
+(NSString *)filename:(NSString *)file
|
||
{
|
||
NSString *path=[FuncPublic getFilePath:file PathType:3];// 要列出来的目录
|
||
// NSLog(@"[FuncPublic filename] reading path: %@", path);
|
||
|
||
NSFileManager* fm=[NSFileManager defaultManager];
|
||
if([fm fileExistsAtPath:path]){
|
||
NSArray *files = [fm subpathsAtPath: path];
|
||
// NSLog(@"[FuncPublic filename] files found in %@: %@", file, files);
|
||
|
||
for (NSString *name in files) {
|
||
// 过滤隐藏文件和 .DS_Store
|
||
if (![name hasPrefix:@"."] && ![name isEqualToString:@".DS_Store"]) {
|
||
// NSLog(@"[FuncPublic filename] filename found: %@", name);
|
||
return name;
|
||
}
|
||
}
|
||
} else {
|
||
// NSLog(@"[FuncPublic filename] Path does not exist: %@", path);
|
||
}
|
||
return @"";
|
||
}
|
||
//去除单引号
|
||
+(NSString *)danbian:(NSString *)str
|
||
{
|
||
return [str stringByReplacingOccurrencesOfString:@"'" withString:@""];
|
||
}
|
||
|
||
|
||
+ (BOOL)isBlankString:(NSString *)string{
|
||
|
||
if (string == nil) {
|
||
|
||
return YES;
|
||
|
||
}
|
||
|
||
if (string == NULL) {
|
||
|
||
return YES;
|
||
|
||
}
|
||
|
||
if([string isEqualToString:@""]){
|
||
return YES;
|
||
}
|
||
|
||
if ([string isKindOfClass:[NSNull class]]) {
|
||
|
||
return YES;
|
||
|
||
}
|
||
|
||
if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]==0) {
|
||
|
||
return YES;
|
||
|
||
}
|
||
|
||
return NO;
|
||
|
||
}
|
||
@end
|