<天下泉城>項目總結

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.lxweimin.com/p/fb20bce230d9 //改變UIButton的相對布局
http://www.lxweimin.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.lxweimin.com/p/ef738baf8e33
代碼示例:

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

五、調用系統功能與跳轉到系統設置

借鑒資料:
http://www.lxweimin.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.lxweimin.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.lxweimin.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:@"服務器繁忙,請稍后再試"];
}
如有錯誤 歡迎指正
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容