该效果基于MenuBarController实现,以处理嵌套手势问题
demo地址:https://github.com/ColdChains/MenuBarController.git
demo已上传Cocoapods,使用:pod ‘MenuBarController’
// 自定义topView
let bar = UIView(frame: CGRect(x: (UIScreen.main.bounds.size.width - 30) / 2, y: 10, width: 30, height: 4))
bar.backgroundColor = .lightGray
bar.layer.cornerRadius = 2
let topView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 44))
topView.backgroundColor = .yellow
topView.addSubview(bar)
let vc = PresentViewController()
let pmbc = PresentMenuBarController()
pmbc.menuBar = topView;
pmbc.topCornerRadius = 16;
pmbc.viewControllers = [vc]
// 自定义高度 也可通过协议修改
// pmbc.minHeight = 200;
// pmbc.middleHeight = 400;
// pmbc.maxHeight = 600;
// pmbc.defaultHeight = .middle;
// 接管状态栏样式
pmbc.modalPresentationStyle = .custom
pmbc.modalPresentationCapturesStatusBarAppearance = true
present(pmbc, animated: true, completion: nil)
通过协议修改配置:
extension PresentViewController: PresentMenuBarControllerDataSource {
// 最小高度
func presentMenuBarControllerMinHeight(_ presentMenuBarController: PresentMenuBarController) -> CGFloat {
return 200
}
func presentMenuBarControllerMiddleHeight(_ presentMenuBarController: PresentMenuBarController) -> CGFloat {
return 400
}
// 最大高度
func presentMenuBarControllerMaxHeight(_ presentMenuBarController: PresentMenuBarController) -> CGFloat {
return 600
}
// 初始化高度
func presentMenuBarControllerDefaultHeight(_ presentMenuBarController: PresentMenuBarController) -> PresentMenuBarController.ContentHeight {
return .middle
}
}