Hermes-chayelheinsen 1.0.3

Hermes-chayelheinsen 1.0.3

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布最新版本2015年9月
SPM支持 SPM

Chayel Heinsen 维护。



  • JP McGlone 和 Chayel Heinsen

hermes logo

hermes text

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。

如何使用

只需两步即可使用!

  1. 创建一个或多个通知
  2. 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])

就这么简单!

hermes success notification

继承赫尔墨斯通知视图

继承赫尔墨斯通知视图非常简单,并且让您可以自由地将视图做得尽可能简单或复杂。

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
    }

您可以为赫尔墨斯通知打标签以帮助确定使用哪种自定义赫尔墨斯通知视图,或者始终返回您自定义的通知视图。这取决于您!