Build Status Carthage compatible CocoaPods Platform Language

Twitter

Panels 是一个框架,可以轻松地向您的应用程序添加滑动面板。它可以处理新设备中的安全区域,并在键盘显示/隐藏时移动您的面板。

已更新至 Swift 5.1

Sliding Panel demo1 Sliding Panel demo2 Sliding Panel demo3

用法

首先,创建您自己的面板,您可以使用 Interface Builder,并参考提供的示例。确保您遵循 Panelable 协议

import UIKit
import Panels

class PanelOptions: UIViewController, Panelable {
    @IBOutlet var headerHeight: NSLayoutConstraint!
    @IBOutlet var headerPanel: UIView!
}

此协议定义了将滑动面板调整到容器、展开和折叠所需的接口。它将处理安全区域。

然后在您的 ViewController 中,显示面板的位置。

class YourViewController: UIViewController {
    lazy var panelManager = Panels(target: self)
    override func viewDidLoad() {
        super.viewDidLoad()
        let panel = UIStoryboard.instantiatePanel(identifier: "YourPanelName")
        let panelConfiguration = PanelConfiguration(size: .oneThird)
        
        // To present the panel
        panelManager.show(panel: panel, config: panelConfiguration)
        ....
        // To dismiss the panel
        panelManager.dismiss()
    }
}

如果您想在面板显示、折叠或展开时收到通知,只需遵循 PanelNotifications 协议。

您可以在 PanelConfiguration 对象中找到额外的选项。

    /// Storyboard name, the first Viewcontroller will be instantiated
    public var panelName: String

    /// Panel height
    public var panelSize: PanelDimensions

    /// Panel margins between the header and the next views.
    public var panelMargin: CGFloat

    /// Visible area when the panel is collapsed
    public var panelVisibleArea: CGFloat

    /// Safe area is avoided if this flag is true.
    public var useSafeArea = true

    /// Collapse and expand when tapping the header view.
    public var respondToTap = true

    /// Collapse and expand when dragging the header view.
    public var respondToDrag = true

    /// Collapse when tapping outside the panel
    public var closeOutsideTap = true

    /// Animate the panel when the superview is shown.
    public var animateEntry = false

    /// If parent view is a navigationcontroller child, this flag allow a better calculation when the panelSize is .fullScreen
    public var enclosedNavigationBar = true

您可以添加一个箭头指示器,以便为您的面板提供更多反馈。 Panels 的完美伴侣是 Arrows

Arrows Example

安装

CocoaPods

pod "Panels" 行添加到您的 Podfile

Carthage

github "antoniocasero/Panels" 行添加到您的 Cartfile

SPM

dependencies: [
  .package(url: "https://github.com/antoniocasero/Panels.git", from: "2.2.3")
]

作者

项目由 Antonio Casero 创建 (@acaserop 在 Twitter 上)。

鸣谢

Sketch UI (Elements)