TDNotificationPanel 是一个可以插入的类,用于显示一个可以包含标题、子标题、图标、进度条或活动指示器的通知。
直到版本 1.0,API 会有所变化。
TDNotificationPanel 在 iOS 6+ 上进行了测试,并需要 ARC。它依赖于以下 Apple 框架
将位于 TDNotificationPanel
目录下的以下文件添加到您的项目中。然后, wherever 您需要 TDNotificationPanel,使用 #import "TDNotificationPanel.h"
包含它。
有 3 种不同的通知类型,分别是
有 3 种不同的通知模式,分别是
请注意,当使用 TDNotificationModeActivityIndicator 和 TDNotificationModeProgressBar 时,将使用 TDNotificationTypeMessage 通知类型。
要显示通知面板,请使用以下方法
[TDNotificationPanel showNotificationInView:self.view
title:@"Notification Title"
subtitle:@"Notification Subtitle"
type:TDNotificationTypeError
mode:TDNotificationModeText
dismissible:YES
hideAfterDelay:3];
如果您需要使用进度条运行长时间任务,请使用以下方法
TDNotificationPanel *panel = [[TDNotificationPanel alloc] initWithView:self.view
title:@"Posting Message"
subtitle:nil
type:TDNotificationTypeMessage
mode:TDNotificationModeProgressBar
dismissible:NO];
[[self view] addSubview:panel];
[panel show];
[self longRunningTaskWithProgress:^(float)progress {
[panel setProgress:progress];
} completion:^{
[panel hideAfterDelay:3];
}];
可以设置完成处理程序,并在通知消失时调用。
[TDNotificationPanel showNotificationInView:self.view
title:@"Notification Title"
subtitle:@"Notification Subtitle"
type:TDNotificationTypeError
mode:TDNotificationModeText
dismissible:YES
hideAfterDelay:3
completionHandler:^{
NSLog(@"Completion Handler");
];
所有通知都添加到一个队列并按顺序显示。
[TDNotificationPanel showNotificationInView:self.view
title:@"Notification 1"
subtitle:@"Notification 1 Subtitle"
type:TDNotificationTypeError
mode:TDNotificationModeText
dismissible:YES
hideAfterDelay:3];
[TDNotificationPanel showNotificationInView:self.view
title:@"Notification 2 Title"
subtitle:@"Notification 2 Subtitle"
type:TDNotificationTypeSuccess
mode:TDNotificationModeText
dismissible:YES
hideAfterDelay:3];
TDNotificationPanel 在 MIT 许可证 下发行。
更新日志可在此处查看此处。