Skip to content

Instantly share code, notes, and snippets.

@fhefh2015
fhefh2015 / new_gist_file
Last active May 17, 2016 06:12
多图下载
//
// TableViewController.m
// 多图下载
//
#import "TableViewController.h"
#import "KMCGeigerCounter.h"
#import "CellData.h"
@interface TableViewController ()
@fhefh2015
fhefh2015 / new_gist_file
Created April 20, 2016 03:23
GCD常用函数
//延迟执行任务函数dispatch_after
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSLog(@"start");
//dispatch_after 是异步执行的
//队列只决定在哪个线程中执行任务 并不能决定执行时间
/**
* 第一个参数: 在哪个时间点执行
* dispatch_time(从哪个时间点开始,经历多少纳秒)
* 第二个参数: 在哪个队列中执行block任务
* 第三个参数: block任务
@fhefh2015
fhefh2015 / new_gist_file
Created May 2, 2016 14:47
iOS防止按钮快速连续点击造成多次响应的方法
//1.在每次点击时先取消之前的操作
- (void)buttonClicked:(id)sender
{
//这里是关键,点击按钮后先取消之前的操作,再进行需要进行的操作
[[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(buttonClicked:) object:sender];
[self performSelector:@selector(buttonClicked: )withObject:sender afterDelay:0.2f];
}
//2.点击后将按钮置为不可点击状态,几秒后恢复
-(void)buttonClicked:(id)sender{
self.button.enabled = NO;
@fhefh2015
fhefh2015 / new_gist_file
Created May 6, 2016 06:24
iPhone获取状态栏和导航栏尺寸(宽度和高度)
// 状态栏(statusbar)
CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
NSLog(@"status width - %f", rectStatus.size.width); // 宽度
NSLog(@"status height - %f", rectStatus.size.height); // 高度
// 导航栏(navigationbar)
CGRect rectNav = self.navigationController.navigationBar.frame;
NSLog(@"nav width - %f", rectNav.size.width); // 宽度
NSLog(@"nav height - %f", rectNav.size.height); // 高度
@fhefh2015
fhefh2015 / new_gist_file.html
Created May 11, 2016 02:47
css3方法:未知高度宽度居中
<style>
.tips_layer_wrap {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, .7);
z-index: 10000;
}
- (NSArray *)datas {
if (_datas == nil) {
NSMutableArray *temp = [NSMutableArray array];
NSString *path = [[NSBundle mainBundle] pathForResource:@"apps.plist" ofType:nil];
NSArray *arr = [NSArray arrayWithContentsOfFile:path];
for (NSDictionary *dict in arr) {
CellData *data = [CellData dataWithDict:dict];
[temp addObject:data];
}
@fhefh2015
fhefh2015 / new_gist_file.js
Last active May 17, 2016 06:13
预加载js
//预加载 jQuery版本
!(function() {
var preloader = function(opts) {
var _this = this;
_this.files = opts.files;
_this.current = 0;
_this.progress = opts.progress;
_this.complete = opts.complete;
_this.container = document.createElement("div");
_this.container.style.cssText = "position:absolute;left:-1000px;top:0;width:1px;height:1px;overflow:hidden";
@fhefh2015
fhefh2015 / new_gist_file
Created May 20, 2016 03:36
NSURLSession下载
//1.创建url
NSString *urlStr=@"https://github.com/cnbin/insertDemo/archive/master.zip";
urlStr =[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url=[NSURL URLWithString:urlStr];
//2.创建请求
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
//3.创建会话(这里使用了一个全局会话)并且启动任务
NSURLSession *session=[NSURLSession sharedSession];
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>居中分页DIV CSS DIVCSS5在线案例演示</title>
<style>
a {
text-decoration: none
}
@fhefh2015
fhefh2015 / new_gist_file.lp
Created May 23, 2016 03:04
CABasicAnimation动画
- (void)animationBaseTest {
CABasicAnimation *baseAnimate = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
baseAnimate.toValue = @(0);
baseAnimate.duration = 0.8;
baseAnimate.repeatCount = MAXFLOAT;
baseAnimate.autoreverses = YES;
[self.heart.layer addAnimation:baseAnimate forKey:@"scaleAnimate"];