iOS 半弹窗效果 三段高度

35 篇文章 0 订阅

该效果基于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
    }
    
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值