<天下泉城>项目总结

2016.11.27-2017.02.25

一、 时间与时间戳的相互转换

借鉴资料:
http://blog.csdn.net/laomaoios/article/details/43899551
http://www.superqq.com/blog/2015/06/26/nsdatehe-nsstringxiang-hu-zhuan-huan/
示例代码:

///时间戳转换为时间
+ (NSString *) timestampConversionDate:(NSInteger)time {
NSDate *date=[NSDate dateWithTimeIntervalSince1970:time];
NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"YYYY.MM.dd. HH:mm"];
NSString *timeStr=[dateformatter stringFromDate:date];
return timeStr;
}

二、UIButton的title和image位置变换

借鉴资料:
http://www.jianshu.com/p/fb20bce230d9 //改变UIButton的相对布局
http://www.jianshu.com/p/43c22fa3b42c //扩大UIButton的可点击范围

三、如何异步线程同步请求

示例代码:

 dispatch_group_t group = dispatch_group_create();  
 dispatch_group_enter(group);
 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [strongSelf getAllVideoDataFoundation];//请求数据函数一
        [strongSelf getDataFouncation]; //请求数据函数二
        ...... //请求数据函数N
        dispatch_group_leave(group);
    });
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
    });

四、复制字符串到剪切板

借鉴资料:
http://www.jianshu.com/p/ef738baf8e33
代码示例:

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
[pasteboard setString:copyString];

五、调用系统功能与跳转到系统设置

借鉴资料:
http://www.jianshu.com/p/78db0e46d954
代码示例:

UIWebView *webView = [[UIWebView alloc] init];    
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",number]]]]; //必须加 *tel://*    
[self.view addSubview:webView];

六、更改系统弹出框

借鉴资料:
http://www.jianshu.com/p/51949eec2e9c

七、如何缩小导航栏的点击范围

借鉴资料:
http://www.cocoachina.com/bbs/read.php?tid=80992

//左按钮:在真正按钮的旁边添加一个空白的左视图
self.leftButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, Size(40), Size(40))];  
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:self.leftButton];   
UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc]initWithCustomView:[UIButton buttonWithType:UIButtonTypeCustom]];   
self.navigationItem.leftBarButtonItems =  [NSArray arrayWithObjects:item,spaceItem,nil];    

八、局部或全局隐藏状态栏

借鉴资料:
http://www.jianshu.com/p/4b2aa09bee06
实例代码

if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {       
    [self prefersStatusBarHidden];    
    [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];     
}    
- (BOOL)prefersStatusBarHidden {   
    return YES;    
}

九、UIView渐变颜色值

实例代码

//初始化CAGradientlayer对象,使它的大小为UIView的大小
        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.frame = CGRectMake(0, 0, leftProgressWidth, Size1080(21));
        //设置渐变区域的起始和终止位置(范围为0-1)
        gradientLayer.startPoint = CGPointMake(0, 0.5);
        gradientLayer.endPoint = CGPointMake(0.5 , 1);
        //设置颜色数组
        gradientLayer.colors = @[(__bridge id)[UIColor colorWithRGB:color(f9664d)].CGColor,(__bridge id)[UIColor colorWithRGB:color(f83931)].CGColor];
        //设置颜色分割点(范围:0-1)
        gradientLayer.locations = @[@(0.5f)];
        //将CAGradientlayer对象添加在我们要设置背景色的视图的layer层
        [self.progressView.layer addSublayer:gradientLayer];

十、获取主Window和删除特定View

实例代码:

UIWindow *keywindow = [[UIApplication sharedApplication] keyWindow];  //获取主Window 
[[[[UIApplication sharedApplication]keyWindow] viewWithTag:1234567]removeFromSuperview]; //删除特定的tag值得View

十一、内购Demo

https://github.com/976431yang/YQInAppPurchaseTool
注意:需集成以上Demo里面的内购Tool
实例代码:

///点击虚拟物品按钮之后触发的方法
- (void)buttonClickEvents: (UIButton *)button {
[YFWLHUDManager showInfoMessage:@"正在购买商品"];
if (self.productArray.count > 0) {
    [[YFWLInAppPurchaseTool defaultTool]restorePurchase];
    [[YFWLInAppPurchaseTool defaultTool]buyProduct:((SKProduct *)self.productArray.firstObject).productIdentifier];
}else {
    [YFWLHUDManager showInfoMessage:@"没有可购买的商品"];
}///productArray:productId数组
}
///内购基本设置
- (void) appPurchaseBaseSetting {
    //获取单例
    YFWLInAppPurchaseTool *appPurchase = [YFWLInAppPurchaseTool defaultTool];
    //设置代理
    appPurchase.delegate = self;
    //验证购买结果
    appPurchase.CheckAfterPay = YES;
    //询问消息
    [YFWLHUDManager showInfoMessage:@"商品是否可以购买"];
    //向苹果询问商品是否能够购买
    [appPurchase requestProductsWithProductArray:@[@"123456789"]];
}
#pragma mark - YQInAppPurchaseToolDelegate
///已经获得可购买的商品
- (void)IAPToolGotProducts:(NSMutableArray *)products {
    self.productArray = products;
    if (products.count > 0) {
        [YFWLHUDManager showSuccessMessage:@"成功获取到可购买的商品"];
    }else {
        [YFWLHUDManager showFailureMessage:@"没有获取到可购买的商品"];
    }
}
///支付失败/取消
- (void)IAPToolCanceldWithProductID:(NSString *)productID {
    [YFWLHUDManager showFailureMessage:@"购买失败"];
}
///支付成功,并开始验证
- (void)IAPToolBeginCheckingdWithProductID:(NSString *)productID {
    [YFWLHUDManager showInfoMessage:@"请求成功,正在验证"];
}
///重复验证
- (void)IAPToolCheckRedundantWithProductID:(NSString *)productID {
    [YFWLHUDManager showInfoMessage:@"重复验证"];
}
///商品完全购买成功
- (void)IAPToolBoughtProductSuccessedWithProductID:(NSString *)productID andInfo:(NSDictionary *)infoDic {
    [YFWLHUDManager showSuccessMessage:@"购买成功"];
}
///验证失败
- (void)IAPToolCheckFailedWithProductID:(NSString *)productID andInfo:(NSData *)infoData {
    [YFWLHUDManager showFailureMessage:@"验证失败,已取消购买"];
}
///恢复购买商品
- (void)IAPToolRestoredProductID:(NSString *)productID {
    [YFWLHUDManager showInfoMessage:@"恢复了商品"];
}
///内购系统错误
- (void)IAPToolSysWrong {
    [YFWLHUDManager showFailureMessage:@"服务器繁忙,请稍后再试"];
}
<天下泉城>项目总结_第1张图片
如有错误 欢迎指正

你可能感兴趣的:(<天下泉城>项目总结)