YSModal_customHeight
模态弹框(从下往上),自定义高度,底部与屏幕对齐,顶部为半透明
环境
swift5.0、iOS10.0
使用步骤
1、导入框架
pod 'YSModal_customHeight'
2、导入命名空间
import YSModal_customHeight
使用小技巧
PresentedViewController 使用说明和示例
1、PresentedViewController只需要继承YSModalCustomHeight_presentedVC即可;
如果是UINavigationController,继承YSModalCustomHeight_presentedNavC,无法用差异;
2、如果需要自定义高度和遮罩颜色及透明度,实现相应的方法即可;
import UIKit
class PresentedVC: YSModalCustomHeight_presentedVC {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.orange
}
// 如果不实现此方法,默认为屏幕高度一半
override func ys_setupModalHeight() -> CGFloat {
return 300
}
// 如果不实现方法,遮罩视图默认为黑色、透明度为0.5
override func ys_setupMaskView() -> (backgroundColor: UIColor, alpha: CGFloat) {
return (UIColor.black,0.5)
}
@IBAction func dismissAction(_ sender: UIButton) {
dismiss(animated: true, completion: nil)
}
}
PresentingViewController 使用说明及示例
1、在需要Modal展现的地方,直接present即可,注意,presentedVC一定是YSModalCustomHeight_presentedVC子类对象
import UIKit
class ViewController: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func modalAction(_ sender: UIButton) {
let sb = UIStoryboard(name: "Main", bundle: nil)
let presentedVC = sb.instantiateViewController(withIdentifier: "p") as! YSModalCustomHeight_presentedVC
// Modal展现
present(presentedVC, animated: true, completion: nil)
}
}