测试已测试 | ✗ |
Lang语言 | SwiftSwift |
许可证 | MIT |
发布最新版本 | 2015年9月 |
SPM支持 SPM | ✗ |
由 Chayel Heinsen 维护。
Hermes 是一个简单且健壮的 iOS 内置通知系统,使用 Swift 编写。它支持带有或没有样式的文本、图标、声音、颜色和操作闭包的通知。您可以轻松创建自己的通知模板,并将其添加到 HermesNotification 中任何数量的属性和功能。
Hermes 一次显示所有排队的通知,并通过简单的滑动方式查看它们(如果3秒钟内不触摸任何通知,则会自动动画播放)
在 Swift 中导入
import Hermes
或 Objective-C
#import <Hermes/Hermes.h>
Hermes (公开)
您将使用 Hermes.sharedInstance 来发布通知。您可以让 Hermes 知道何时 wait() 并收集通知,何时 go() 并发布通知,一旦 Hermes 有任何通知。
Notification (公开,可扩展)
通知是一个具有文本、图像、声音和颜色等属性的模型。您可以扩展或子类化通知并在自定义 NotificationViews 中使用它们。
NotificationView (公开,可扩展)
通知视图是一个显示通知的 UIView。Hermes 允许您子类化并显示您自己的符合您应用程序风格的 NotificationViews。
BulletinView (受保护)
BulletinView 是一个显示 1 或多个 NotificationViews 的 UIView。Hermes 不允许您子类化和使用您自己的 BulletinView。
只需两步即可使用!
hermes.postNotifications([...])
创建通知
// uses Hermes singleton
let hermes = Hermes.sharedInstance
// 'Upload Complete!' success Notification
let successNotification = HermesNotification()
successNotification.text = "Upload complete!"
successNotification.image = UIImage(named: "success_icon")
successNotification.color = .greenColor()
// Call self.foo() when the NotificationView for this Notification is tapped
successNotification.action = { notification in
self.foo()
}
// 'Upload failed :(' failure Notification
let failureNotification = HermesNotification()
failureNotification.text = "Upload failed :("
failureNotification.image = UIImage(named: "error_icon")
failureNotification.color = .redColor()
hermes.postNotification(successNotification)
hermes.postNotification(failureNotification)
// we could do use wait(), which tells Hermes to collect notifications without showing them yet
hermes.wait()
// post both the success and failure notification
hermes.postNotification(successNotification)
hermes.postNotification(failureNotification)
// this tells Hermes to post all of the notifications in the queue
hermes.go()
// we could have also done the above code by simply using postNotifications
hermes.postNotifications([successNotification, failureNotification])
就这么简单!
继承赫尔墨斯通知视图非常简单,并且让您可以自由地将视图做得尽可能简单或复杂。
class CustomNotificationView: HermesNotificationView {
override var notification: HermesNotification? {
didSet {
// update your view
}
}
}
接下来您需要实现这个赫尔墨斯代理
hermes.delegate = self
以及代理方法
func hermesNotificationViewForNotification(#hermes: Hermes, notification: HermesNotification) -> HermesNotificationView? {
if notification.tag == kCustomNotificationTag {
return CustomNotificationView()
}
return nil
}
您可以为赫尔墨斯通知打标签以帮助确定使用哪种自定义赫尔墨斯通知视图,或者始终返回您自定义的通知视图。这取决于您!