首页 > 解决方案 > 与控制中心相同的当前 ViewController 在 iPhone 中工作

问题描述

我想在单击按钮时以所附屏幕截图中显示的方式显示底部工作表。

我熟悉正常的当前屏幕,即使是透明背景。但是,我真的不确定如何实现这个 UI。因此,我没有附加任何代码,因为我仍在寻找它。任何帮助表示赞赏!谢谢!

在此处输入图像描述

标签: iosuser-interfaceswift5bottom-sheetpresentviewcontroller

解决方案


考虑使用 FloatingPanel

查看这个 GitHub 项目: https ://github.com/scenee/FloatingPanel

let  = FloatingPanelController()
let contentVC = YOUR_VIEW_CONTROLLER()
floatingPanel.set(contentViewController: contentVC)
self.present(floatingPanel, animated: true, completion: nil)

让它可以通过向下滑动来移除

floatingPanel.isRemovalInteractionEnabled = true

要自定义浮动面板,您需要使用“浮动面板布局”协议实现布局

class ViewController: UIViewController, FloatingPanelControllerDelegate {
    ... {
        floatingPanel = FloatingPanelController(delegate: self)
        floatingPanel.layout = MyFloatingPanelLayout()
    }
}

class MyFloatingPanelLayout: FloatingPanelLayout {
    let position: FloatingPanelPosition = .bottom
    let initialState: FloatingPanelState = .tip
    var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] {
        return [
            .full: FloatingPanelLayoutAnchor(absoluteInset: 16.0, edge: .top, referenceGuide: .safeArea),
            .half: FloatingPanelLayoutAnchor(fractionalInset: 0.5, edge: .bottom, referenceGuide: .safeArea),
            .tip: FloatingPanelLayoutAnchor(absoluteInset: 44.0, edge: .bottom, referenceGuide: .safeArea),
        ]
    }
}

推荐阅读