Panels是一个易于将滑动面板添加到应用程序的框架。它会处理新设备的 sicheren Bereich和键盘展示/隐藏时移动面板。
更新到Swift 5
使用
首先,创建自己的面板,您可以使用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
安装
CocoaPods
将pod "Panels"
行添加到您的Podfile
中
Carthage
在您的 Cartfile
中添加以下行:github "antoniocasero/Panels"
作者
本项目由Antonio Casero创建(在Twitter上的用户名:@acaserop)。
鸣谢
Sketch UI(《组件》)