CFNotify
CFNotify 使用 Swift 编写,使用 UIKit Dynamics
作为动画器。它可以使任何 `UIView` 对象变得 可拖动 和 可抛掷。此库主要用于 应用内通知 和 警报。让我们以更互动和有趣的方式通知并提醒您的用户!
特性
- 与任何 UIView 对象一起工作!
- 使用 UIKit Dynamics。轻量级和流畅!
- 高度可定制
- 包含 三个 即用型视图:
CyberView
,ClassicView
,ToastView
- 简单实现
要求
- Swift 4.0+
- Xcode 9
- iOS 9.0+
变更日志
请阅读 CHANGELOG.md。
安装
-
Carthage (推荐)
将以下行添加到 Cartfile
#CFNotify github "hallelujahbaby/CFNotify"
运行
carthage update
并将 CFNotify.framework 和 CFResources.bundle 添加到您的项目中 -
Cocoapods
将以下行添加到 Podfile
pod "CFNotify"
入门
基础
这是具有所有 默认 设置的基本功能,设计您自己的 UIView
或使用 CFNotifyView
来创建一个。
CFNotify.present(view: UIView)
如果您需要更多的 自定义 设置,创建您自己的 Config
并使用以下功能。
CFNotify.present(config: Config, view: UIView)
如果您想要 自定义 的 tap
操作,请使用以下功能。(如果您使用 tapHandler,则会覆盖默认的点击以隐藏操作)
CFNotify.present(config: Config, view: UIView, tapHandler: (()->Void)?)
CFNotify 将所有要显示的视图放入队列(先进先出)。您可以使用以下函数编程方式隐藏视图。
CFNotify.hide() // hide the current view
CFNotify.hideAll() // hide all the views in queue (Clear the queue)
CFNotifyView
您可以使用CFNotifyView
类快速简单地创建一个警报视图。
CFNotifyView
目前包括 3 种 视图:Cyber
,Classic
,Toast
。
每种风格都有 4 种 主题:信息
、成功
、失败
、警告
每个主题都有 2 种 样式:浅色
和深色
-
网络风
let cyberView = CFNotifyView.cyberWith(title: "Title", body: "Body", theme: .Info(.Light)) //More customizations let customCyberView = CFNotifyView.cyberWith(titleFont: UIFont, titleColor: UIColor, bodyFont: UIFont, bodyColor: UIColor, backgroundColor: UIColor, blurStyle: UIBlurEffectStyle)
-
经典式
let classicView = CFNotifyView.classicWith(title: "Title", body: "Body", theme: .Success(.Light)) //More customizations let customClassicView = CFNotifyView.classicWith(titleFont: UIFont, titleColor: UIColor, bodyFont: UIFont, bodyColor: UIColor, backgroundColor: UIColor)
-
吐司
let toastView = CFNotifyView.toastWith(text: "Text", theme: .Fail(.Dark)) //More customizations let customToastView = CFNotifyView.toastWith(text: String, textFont: UIFont, textColor: UIColor, backgroundColor: UIColor)
配置
您可以使用Config
类来配置CFNotify
。该类包含许多属性,以下三个是最常见的:
initPosition
:视图出生的位置appearPosition
:视图显示的位置hideTime
:视图将在hideTime
后自动隐藏(默认为3秒)
示例
var classicViewConfig = CFNotify.Config()
classicViewConfig.initPosition = .top(.random) //the view is born at the top randomly out of the boundary of screen
classicViewConfig.appearPosition = .top //the view will appear at the top of screen
classicViewConfig.hideTime = .never //the view will never automatically hide
委托
CFNotify
为一些常见事件提供了 委托 方法。您需要遵守 CFNotifyDelegate
。
func cfNotifyDidAppear() {}
func cfNotifyStartDragging(atPoint: CGPoint) {}
func cfNotifyIsDragging(atPoint: CGPoint) {}
func cfNotifyEndDragging(atPoint: CGPoint) {}
func cfNotifyDidDisappear() {}
func cfNotifyIsTapped() {}
待办事项列表
- 添加 SPM 支持
- 改进示例应用
- 添加带按钮的提醒视图
- 完整文档
错误和问题
如果您发现任何错误或遇到任何与此框架相关的问题,请随意在 问题页面 中打开新的问题。
贡献
欢迎您为此项目做出贡献,请随意 提交拉取请求。