Skip to content

Instantly share code, notes, and snippets.

View ethanbing's full-sized avatar

Eric ethanbing

View GitHub Profile
@ethanbing
ethanbing / gist:3ff9ab56cab5b0edc2fc
Created November 5, 2014 04:20
UICollectionView 点击空白 继续传递事件
继承并实现
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[[self nextResponder] touchesBegan:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch * touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
@ethanbing
ethanbing / gist:f844fe8ec24f44a502f0
Created October 29, 2014 01:38
iOS判断版本
1. iOS版本确认
- (void)viewDidLoad {
[super viewDidLoad];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.0) {
bannerView = [[ADBannerView alloc] init];
bannerView.delegate = self;
[self.view addSubview:bannerView];
}
2. 新类是否存在
@ethanbing
ethanbing / gist:70869e43d21c41afac67
Created October 23, 2014 06:41
崩溃后程序保持运行状态而不退出
//崩溃后程序保持运行状态而不退出
CFRunLoopRef runLoop = CFRunLoopGetCurrent();  
    CFArrayRef allModes = CFRunLoopCopyAllModes(runLoop);  
      
    while (!dismissed)  
    {  
        for (NSString *mode in (__bridge NSArray *)allModes)  
        {  
            CFRunLoopRunInMode((__bridge CFStringRef)mode, 0.001, false);  
        }  
@ethanbing
ethanbing / shi
Created August 23, 2014 08:05
调整8小时差
NSDate *date = [NSDate date];
// 调整8小时时差
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate:date];
NSDate *localeDate = [date dateByAddingTimeInterval: interval];
@ethanbing
ethanbing / 0_reuse_code.js
Created August 23, 2014 05:13
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
//绘制三角
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextBeginPath(context);
CGContextMoveToPoint (context, CGRectGetMinX(rect), CGRectGetMaxY(rect));
CGContextAddLineToPoint(context, CGRectGetMidX(rect), CGRectGetMinY(rect));
CGContextAddLineToPoint(context, CGRectGetMaxX(rect), CGRectGetMaxY(rect));
CGContextClosePath(context);
@ethanbing
ethanbing / gist:10970615
Created April 17, 2014 10:05
iOS 常用数学函数
1、 三角函数 
  double sin (double);正弦 
  double cos (double);余弦 
  double tan (double);正切 
  2 、反三角函数 
  double asin (double); 结果介于[-PI/2, PI/2] 
  double acos (double); 结果介于[0, PI] 
  double atan (double); 反正切(主值), 结果介于[-PI/2, PI/2] 
  double atan2 (double, double); 反正切(整圆值), 结果介于[-PI, PI] 
  3 、双曲三角函数 
@ethanbing
ethanbing / gist:9927019
Created April 2, 2014 02:30
AFNetwork上传图片
AFHTTPRequestOperation * operation = [_AFManager POST:[_baseURL stringByAppendingString:MCSetavatarInterface] parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileURL:[dic objectForKey:@"url"] name:@"avatar" error:nil];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
@ethanbing
ethanbing / gist:9887461
Created March 31, 2014 08:04
获得appDelegat单例对象
+ (AppDelegate *)sharedAppDelegate {
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
@ethanbing
ethanbing / gist:9829815
Created March 28, 2014 10:35
获取程序的Documents路径
/**
 Returns the path to the application's documents directory.
 */
- (NSString *)applicationDocumentsDirectory {
     
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
    return basePath;
}