今日學(xué)習(xí)

二零一七年八月二十

pod install | pod update

  • pod install 通常使用點(diǎn)

    • 安裝cocoapods;
    • podfile中添加、刪除,新依賴庫;
    • 修改podfile中指定依賴庫版本號;
      每次執(zhí)行pod install命令會先遵循podfile文件中的改動信息,然后再遵循podfile.lock文件而執(zhí)行命令。
  • pod update通常使用點(diǎn):

    • pod update 更新所有依賴庫版本;
    • pod update PODNAME 更新指定依賴庫版本;
      pod update命令會遵循podfile文件指令下,從而更新依賴庫。若未指定依賴庫版本,則會默認(rèn)更新到最新版本,然后會生成新的podfile.lock文件。

Podfile.lock

作用:跟蹤,鎖定,podfile文件中依賴庫的版本。

第一次運(yùn)行pod install命令時,會生成此文件,此文件會鎖定你****此時****podfile文件中的版本。
之后每次修改podfile文件,或運(yùn)行pod update命令時,會重新生成此文件。

Manifest.lock

Manifest.lock 是 Podfile.lock 的副本,每次只要生成 Podfile.lock 時就會生成一個一樣的 Manifest.lock 存儲在 Pods 文件夾下。在每次項(xiàng)目 Build 的時候,會跑一下腳本檢查一下 Podfile.lock 和 Manifest.lock 是否一致。

參考:

pod install vs. pod update

關(guān)于 Podfile.lock 帶來的痛


二零一七年八月十八

iOS原生與H5交互

  • JS給OC傳消息

    1、攔截跳轉(zhuǎn)的方式

    JS這邊發(fā)請求,iOS把請求攔下來,再扒出請求url里的字符串,再各種截取得 到有用的數(shù)據(jù)

    UIWebView 用來監(jiān)聽請求觸發(fā)也是通過 UIWebView 相關(guān)的 delegate    method:
    web?View(_:?should?Start?Load?With:?navigation?Type:?) 
    官方文檔,方法中返回一個 Boolean,來判定是否讓請求繼續(xù)執(zhí)行。
    
    2、JavaScriptCore

    JS調(diào)用OC函數(shù)(代碼塊),給OC值(參數(shù)),讓OC做一些事情。傳值、方法 命名都按web前端開發(fā)人員來定義。兩端做適配。

  • OC給JS傳消息

    OC調(diào)用JS函數(shù)給JS傳值,JS函數(shù)接到此值(參數(shù))做一些事情。

    即: Objective-C執(zhí)行JavaScript代碼:

    // 獲取當(dāng)前頁面的title
    NSString *title = [webview    stringByEvaluatingJavaScriptFromString:@"document.title"];
    
    // 獲取當(dāng)前頁面的url
    NSString *url = [webview    stringByEvaluatingJavaScriptFromString:@"document.location.href"];
    
    例子:彈窗
    • 第一種方式: WebView直接調(diào)用 stringByEvaluatingJavaScriptFromString屬性
    [webView stringByEvaluatingJavaScriptFromString:@"alert('test js OC')"];
    
    • 第二種方式: JavaScriptCore
    JSContext *context=[webView    valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
    NSString *alertJS=@"alert('test js OC')"; //準(zhǔn)備執(zhí)行的js代碼
    [context evaluateScript:alertJS];//通過oc方法調(diào)用js的alert
    
    • 第三種就是使用WKWebview

    參考:

    Objective-C與JavaScript交互的那些事

    OC調(diào)JS |
    JS調(diào)OC

    關(guān)于iOS7里的JavaScriptCore framework


二零一七年八月十七

iOS 中 Cocoapods 的 Bundle

cocoapods 管理圖片資源和字體庫

如何加載cocoapods中的資源圖片?
  • 1、去PodBundle中取獲取資源圖片
+ (UIImage *)ht_imageNamed:(NSString *)name ofType:(nullable NSString *)type {
    NSString *mainBundlePath = [NSBundle mainBundle].bundlePath;
    NSString *bundlePath = [NSString stringWithFormat:@"%@/%@",mainBundlePath,@"SMPagerTabView.bundle"];
    NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];
    if (bundle == nil) {
        bundlePath = [NSString stringWithFormat:@"%@/%@",mainBundlePath,@"Frameworks/CcfaxPagerTab.framework/SMPagerTabView.bundle"];
        bundle = [NSBundle bundleWithPath:bundlePath];
    }
    if ([UIImage respondsToSelector:@selector(imageNamed:inBundle:compatibleWithTraitCollection:)]) {
        return [UIImage imageNamed:name inBundle:bundle compatibleWithTraitCollection:nil];
    } else {
        return [UIImage imageWithContentsOfFile:[bundle pathForResource:name ofType:type]];
    }
}

    // fix:真機(jī)加載不到Bundle中資源圖片。 date:20170816
    NSBundle *frameworkBundle = [NSBundle bundleForClass:self.class];
    NSURL *bundleURL = [[frameworkBundle resourceURL] URLByAppendingPathComponent:@"SMPagerTabView.bundle"];
    NSBundle *resourceBundle = [NSBundle bundleWithURL:bundleURL];
    UIImage *image = [UIImage imageNamed:@"shadowImg" inBundle:resourceBundle compatibleWithTraitCollection:nil];
    self.shadowImgView.image = image;

二零一七年八月二號

  • topLayoutGuide & bottomLayoutGuide
  • topLayoutGuide表示Y軸的最高點(diǎn)限制,表示不希望被Status Bar或Navigation Bar遮擋的視圖最高位置。
  • bottomLayoutGuide表示Y軸的最低點(diǎn)限制,表示不希望被UITabbarController遮擋的視圖最低點(diǎn)距離supviewlayout的距離。
  • frame & bounds
  • frame就是相對于父視圖的布局位置與大小:
  • bounds與frame最大的不同就是坐標(biāo)系不同,bounds原點(diǎn)始終是(0,0),而frame的原點(diǎn)則不一定,而是相對于其父視圖的坐標(biāo)。

閱讀文章:

  1. UIViewControllerUIViewController生命周期

  2. Cocoa-Swift-UIViewController布局Tips

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容