二零一七年八月二十
pod install
| pod update
-
pod install
通常使用點- 安裝cocoapods;
- podfile中添加、刪除,新依賴庫;
- 修改podfile中指定依賴庫版本號;
每次執行pod install
命令會先遵循podfile
文件中的改動信息,然后再遵循podfile.lock文件而執行命令。
-
pod update
通常使用點:-
pod update
更新所有依賴庫版本; -
pod update PODNAME
更新指定依賴庫版本;
pod update
命令會遵循podfile
文件指令下,從而更新依賴庫。若未指定依賴庫版本,則會默認更新到最新版本,然后會生成新的podfile.lock
文件。
-
Podfile.lock
作用:跟蹤,鎖定,podfile
文件中依賴庫的版本
。
第一次運行pod install
命令時,會生成此文件,此文件會鎖定你****此時****podfile
文件中的版本。
之后每次修改podfile
文件,或運行pod update
命令時,會重新生成此文件。
Manifest.lock
Manifest.lock 是 Podfile.lock 的副本,每次只要生成 Podfile.lock 時就會生成一個一樣的 Manifest.lock 存儲在 Pods 文件夾下。在每次項目 Build 的時候,會跑一下腳本檢查一下 Podfile.lock 和 Manifest.lock 是否一致。
參考:
二零一七年八月十八
iOS原生與H5交互
-
JS給OC傳消息
1、攔截跳轉的方式
JS這邊發請求,iOS把請求攔下來,再扒出請求url里的字符串,再各種截取得 到有用的數據
UIWebView 用來監聽請求觸發也是通過 UIWebView 相關的 delegate method: web?View(_:?should?Start?Load?With:?navigation?Type:?) 官方文檔,方法中返回一個 Boolean,來判定是否讓請求繼續執行。
2、JavaScriptCore
JS調用OC函數(代碼塊),給OC值(參數),讓OC做一些事情。傳值、方法 命名都按web前端開發人員來定義。兩端做適配。
-
OC給JS傳消息
OC調用JS函數給JS傳值,JS函數接到此值(參數)做一些事情。
即: Objective-C執行JavaScript代碼:
// 獲取當前頁面的title NSString *title = [webview stringByEvaluatingJavaScriptFromString:@"document.title"]; // 獲取當前頁面的url NSString *url = [webview stringByEvaluatingJavaScriptFromString:@"document.location.href"];
例子:彈窗
- 第一種方式:
WebView
直接調用stringByEvaluatingJavaScriptFromString
屬性
[webView stringByEvaluatingJavaScriptFromString:@"alert('test js OC')"];
- 第二種方式:
JavaScriptCore
JSContext *context=[webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"]; NSString *alertJS=@"alert('test js OC')"; //準備執行的js代碼 [context evaluateScript:alertJS];//通過oc方法調用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、真機獲取不到
pod
中的資源bundle
,所以圖片顯示不出來??梢赃@樣取cocoapods
中的bundle
資源圖片
How to load resource in cocoapods resource_bundle
// fix:真機加載不到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軸的最高點限制,表示不希望被Status Bar或Navigation Bar遮擋的視圖最高位置。
- bottomLayoutGuide表示Y軸的最低點限制,表示不希望被UITabbarController遮擋的視圖最低點距離supviewlayout的距離。
- frame & bounds
- frame就是相對于父視圖的布局位置與大小:
- bounds與frame最大的不同就是坐標系不同,bounds原點始終是(0,0),而frame的原點則不一定,而是相對于其父視圖的坐標。
閱讀文章: