前言
受Flutter bottomSheet,drawer,dialog, 響應(yīng)式布局的啟發(fā)得封。也有基于Swift編寫一套通用的彈窗組件的想法米诉,所以寫了JFPoup組件,帶有3種彈窗風(fēng)格凶硅,分別是drawer(抽屜式)悠咱,bottomSheet(底部往上彈出UIView容器),dialog(對話框,也就是Alert),都能彈出自定義的UIView容器贾虽√釉悖基于Swift編寫,OC若要兼容要寫相應(yīng)擴展蓬豁,詳情可以看demo绰咽。JFPopup 目前支持iOS9+
下載地址
cocoaPods:
pod 'JFPopup', '1.0.0'
github:
https://github.com/JerryFans/JFPopup
Usage
快速模式
Dialog
對話框模式,類似UIAlertConroller, 你也可以編寫你的自定義AlertView
self.popup.dialog {
let v = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
v.backgroundColor = .red
return v
}
image
Drawer
抽屜模式地粪,支持左右抽屜取募,寬度自定義,最大可以全屏驶忌,
//default left
self.popup.drawer {
let v = DrawerView(frame: CGRect(x: 0, y: 0, width: CGSize.jf.screenWidth(), height: CGSize.jf.screenHeight()))
v.closeHandle = { [weak self] in
self?.popup.dismiss()
}
return v
}
self.popup.drawer(with: .right) {
let v = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: CGSize.jf.screenHeight()))
v.backgroundColor = .red
return v
}
image
Bottomsheet
類似Flutter Bottomsheet, 底部往上彈出一個容器矛辕。 你也可以給予此創(chuàng)建你的個人自定義風(fēng)格UIActionSheet. 底下有微信風(fēng)格的組件已封裝
self.popup.bottomSheet {
let v = UIView(frame: CGRect(x: 0, y: 0, width: CGSize.jf.screenWidth(), height: 300))
v.backgroundColor = .red
return v
}
image
通用組件
v1.0,暫時只有一款微信風(fēng)格ActionSheet, 基于上面bottomSheet打造笑跛,后續(xù)會基于上面基礎(chǔ)popup,打造更多基礎(chǔ)組件
self.popup.actionSheet {
[
JFPopupAction(with: "拍攝", subTitle: "照片或視頻照片", clickActionCallBack: { [weak self] in
self?.pushVC()
}),
JFPopupAction(with: "從手機相冊選擇", subTitle: nil, clickActionCallBack: {
}),
JFPopupAction(with: "用秒剪制作視頻", subTitle: nil, clickActionCallBack: {
}),
]
}
image
VC模式創(chuàng)建
此方法推薦兼容OC情況下使用,或者你的popup View代碼量非常大 需要一個vc來管理聊品。
繼承寫法 (類似繼承UITableView,dataSoure寫在內(nèi)部)
var config = JFPopupConfig.bottomSheet
config.isDismissible = false
let vc = TestCustomViewController(with: config)
vc.show(with: self)
閉包寫法
var config = JFPopupConfig.dialog
config.bgColor = .clear
let vc = JFPopupController(with: config, popupProtocol: self) {
let view: UIView = {
let view = UIView()
view.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
view.layer.cornerRadius = 12
view.backgroundColor = .black
return view
}()
return view
}
vc.show(with: self)