ContentSheet 0.1.5

ContentSheet 0.1.5

测试已测试
Lang语言 SwiftSwift
许可证 Apache 2
发布最新发布2017年8月
SwiftSwift版本3.0
SPM支持SPM

Rajat Gupta维护。



  • 作者
  • rajatgupta26

ContentSheet

示范

Demo

示例

要运行示例项目,请克隆仓库,然后先从Example目录运行pod install

要求

安装

ContentSheet可通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中

pod "ContentSheet"

用法

ContentSheet可以呈现任何遵循'ContentSheetContentProtocol'的对象。例如项目和示范显示如何通过一些自定义对象/控制器呈现UIView、UIViewController、UINavigationController。UIView、UIViewController和UINavigationController扩展默认提供。您可以查看“ContentSheet.swift”文件以获取想法。

要从任何VIEW CONTROLLER呈现 ViewController 或 Navigation Controller

<presenter instance>.present(inContentSheet: <view controller instance>, animated: true)

从内容 VIEW CONTROLLER 中删除内容页

self.dismissContentSheet(animated: true)

在内容页中呈现视图

let contentSheet = ContentSheet(content: <UIView instance>)
<presenter instance>.present(contentSheet, animated: true, completion: completion)

从内容 VIEW 中删除内容页

self.dismissContentSheet(animated: true)

为观察提供滚动视图

override func scrollViewToObserve(containedIn contentSheet: ContentSheet) -> UIScrollView? {
    return <scrollview instance>
}

ContentSheet默认在内容上方显示导航栏。要控制这种行为,请使用ContentSheet实例的这个属性

public var showDefaultHeader: Bool = true

如果您在ContentSheet中呈现了UIViewController,默认标题将采用视图控制器的navigationItem并推进默认导航栏的堆栈。这意味着就像在UINavigationController的情况下,您的视图控制器navigationItem的标题和左、右栏按钮将默认显示在顶部。如果没有左栏按钮,内容页将显示一个关闭按钮。

如果您呈现的是UIViewController之外的内容,请使用ContentSheetContentProtocol中的此属性

@objc optional var navigationItem: UINavigationItem { get }

如果您需要访问默认导航栏或项,请使用内容页实例的这个属性

public var contentNavigationBar: UINavigationBar?
public var contentNavigationItem: UINavigationItem?

您可以使用这些来自定义导航项的内容。或者,简单地禁用默认标题使用swift showDefaultHeader,然后制作整个内容。

如果存在 UIViewController 实例展示了,此便捷方法允许你访问顶部的导航栏

public func cs_navigationBar()

此方法首先检查 UIViewController 实例是否在 navigationController 中。如果是,则返回 navigationController 的导航栏,否则返回内容表的导航栏

使用以下方法来控制折叠和展开的高度

open func collapsedHeight(containedIn contentSheet: ContentSheet) -> CGFloat {
    return <height>
}

open func expandedHeight(containedIn contentSheet: ContentSheet) -> CGFloat {
    return <height>
}

使用以下方法来控制状态栏的显示模式

open func prefersStatusBarHidden(contentSheet: ContentSheet) -> Bool {
    return <should hide?>
}

open func preferredStatusBarStyle(contentSheet: ContentSheet) -> UIStatusBarStyle {
    return <style>
}

open func preferredStatusBarUpdateAnimation(contentSheet: ContentSheet) -> UIStatusBarAnimation {
    return <animation>
}

在 UIViewController 和 UIView 上有便捷方法使用 ‘self.contentSheet()’ 来获取内容表。在 ContentSheet 中还有一个名为 ‘contentSheet(content:)’ 的函数,可以用来获取任何内容的内容表。

还可以查看 ViewController.swiftCustomContent.swift 中的 ‘presentCustomView(_:)’ 函数,以了解如何展示 UIView 或其子类。

使用以下属性来自定义内容表的行为

public var showDefaultHeader: Bool = true
public var blurBackground: Bool = true
public var blurStyle: UIBlurEffectStyle = .dark
public var dismissOnTouchOutside: Bool = true
public var backgroundImage: UIImage? 
public var backgroundView: UIView? 

ContentSheetDelegate

使用代理来获取回调。代理符合‘ContentSheetDelegate’。

当表显示或隐藏时,会发送这些回调。

@objc optional func contentSheetWillShow(_ sheet: ContentSheet)
@objc optional func contentSheetDidShow(_ sheet: ContentSheet)
@objc optional func contentSheetWillHide(_ sheet: ContentSheet)
@objc optional func contentSheetDidHide(_ sheet: ContentSheet)

当内容表视图出现或消失时,会给这些回调。如果你想在出现过渡时更新内容,请使用它们。

@objc optional func contentSheetWillAppear(_ sheet: ContentSheet)
@objc optional func contentSheetDidAppear(_ sheet: ContentSheet)
@objc optional func contentSheetWillDisappear(_ sheet: ContentSheet)
@objc optional func contentSheetDidDisappear(_ sheet: ContentSheet)

ContentSheetContentProtocol

从内容控制器 returning a content view using this

var view: UIView! {get}

从内容控制器 returning a navigation item this

@objc optional var navigationItem: UINavigationItem { get }

使用以下方法为准备内容视图的生命周期事件(在 ContentSheet.swift 中的 UIViewController 扩展中查看)

@objc optional func contentSheetWillAddContent(_ sheet: ContentSheet)
@objc optional func contentSheetDidAddContent(_ sheet: ContentSheet)
@objc optional func contentSheetWillRemoveContent(_ sheet: ContentSheet)
@objc optional func contentSheetDidRemoveContent(_ sheet: ContentSheet)

使用以下方法来配置行为(在 SecondViewController.swiftContentSheet.swift 中的 UIViewController 扩展中查看)

@objc optional func collapsedHeight(containedIn contentSheet: ContentSheet) -> CGFloat
@objc optional func expandedHeight(containedIn contentSheet: ContentSheet) -> CGFloat

@objc optional func scrollViewToObserve(containedIn contentSheet: ContentSheet) -> UIScrollView?

为了了解内容和状态,请使用以下只读变量

public var content: ContentSheetContentProtocol
public var state

展示任何内容的示例

let contentSheet = ContentSheet(content: <ContentSheetContentProtocol instance>)
<presenter instance>.present(contentSheet, animated: true, completion: completion)

作者

rajatgupta26, [email protected]

许可

版权所有 2017 Flipkart Internet Pvt. Ltd.

根据 Apache License 2.0(“许可证”);此文件只能按许可证要求使用。您可以在以下位置获得许可证的副本:

https://apache.ac.cn/licenses/LICENSE-2.0

除非适用法律要求或书面同意,否则根据许可证分发的软件是按照“原样”基础分发的,不提供任何明示或暗示的保证或条件。请参见许可证了解具体语言管理权限和限制。