二零一七年八月二十
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 是否一致。
參考:
二零一七年八月十八
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
參考:
- 第一種方式:
二零一七年八月十七
如何加載cocoapods中的資源圖片?
- 1、去
Pod下Bundle中取獲取資源圖片
+ (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]];
}
}
- 2、真機(jī)獲取不到
pod中的資源bundle,所以圖片顯示不出來??梢赃@樣取cocoapods中的bundle資源圖片
How to load resource in cocoapods resource_bundle
// 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)。
閱讀文章: