1. Cocoapods安装:
(1)介绍:通过 CocoaPods 安装可以最大化地简化安装过程。pod可用来管理第三方库以及私有组件,提供了IOS第三方库管理标准。一方面使项目架构更加清晰,一方面现有的工具Cocoapods提供了近乎完美的解决方案。
(2)Cocoapods官网:「CocoaPods」(https://cocoapods.org/);
备注:「Cocoapods」(https://github.com/CocoaPods/CocoaPods)
(3)安装Cocoapods:

参考:「CocoaPods安装方法」(https://www.jianshu.com/p/f43b5964f582)。
本人在终端输入命令:sudo gem install -n /usr/local/bin cocoapods后安装成功。

2. 使用Cocoapods管理IOS库
2.1 在Xcode 工程中集成Cocoapods
(1)在Xcode项目中生成Cocoapods配置文件

(2)打开配置文件Podfle
生成Cocoapods配置文件Podfle后用文本编辑器打开,如图所示:

2.2 使用Cocoapods管理SWRevealViewController库(其他库同理)
(1)将所需库添加至配置文件Podfle

说明:

(2)更新pod:终端输入命令pod update来从github上下载更新pod,网速不好的话时间可能会长一点

注意:终端需先进入工程目录下, 再输入更新命令。
备注:pod 每天可能都在更新,使用pad update命令可能会安装不上最新pod,故最好使用pad install命令。
(3)关闭当前项目(如:Ofo-demo)后,打开“Ofo-demo.xcwordspace”项目,该项目多了Pods相关文件。


2.3 在Xcode项目中SWRevealViewController的使用
备注:SWRevealViewController是用O-C写的,故在swift项目中需进行桥接
(1)在主工程下新建一个Objective-C的桥接头文件(如命名为h.m)后会自动出现一个Ofo-demo-Bridging-Header.h文件,此时可把h.m已无用可删除。


说明:桥接头文件创建成功后,以后就不需要再创建了,所有用O-C写的需要进行桥接的第三方库都在该文件中进行桥接。
(2)在Pods下找到SWRevealViewController.h文件,在Ofo-demo-Bridging-Header.h文件中导入SWRevealViewController的头文件,即SWRevealViewController.h的l路径。

(3)使用SWRevealViewController:在主项目的.swift文件中使用SWRevealViewController时需先引入,即import SWRevealViewController。

3. 扩展说明
(1)侧边栏组件:「SWRevealViewController」(https://github.com/John-Lluch/SWRevealViewController)
(2)其它侧边栏组件:一般OC的比较稳定一点。

(3)Cocoapods官网搜索SWRevealViewController侧边栏组件库:


网友评论