博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用开源库 TWMessageBarManager 展示系统级别的通知
阅读量:7036 次
发布时间:2019-06-28

本文共 5257 字,大约阅读时间需要 17 分钟。

TWMessageBarManager

简单翻译

An iOS manager for presenting system-wide notifications via a dropdown message bar.

一个iOS的管理类,用来展示系统级别的通知,通过一个下拉的信息条。

Requirements

  • Requires iOS 6.0 or later
  • Requires Automatic Reference Counting (ARC)
  • 需要iOS6.0或以上
  • 需要ARC

Features

  • Drop-in singleton manager supported across all devices.
  • Simple to use protocols and callbacks.
  • Landscape and portrait orientation support.
  • Highly customizable.
  • 单例模式,支持所有的种类的设备
  • 可以使用协议或者block
  • 支持横屏竖屏
  • 高度定制

Refer to the  for an overview of TWMessagBarManager's feature history.

Author

Terry Worona

Tweet me 

Email me at 

Installation

 is the recommended method of installing the TWMessageBarManager.

推荐用CocoPods来安装吧。

The Pod Way

Simply add the following line to your Podfile:

pod 'TWMessageBarManager'

Your podfile should look something like:

platform :ios, '6.0'pod 'TWMessageBarManager', '~> 1.4.0'

The Old School Way

The simpliest way to use TWMessageBarManager with your application is to drag and drop the /Classes folder into you're Xcode 5 project. It's also recommended you rename the /Classes folder to something more descriptive (ie. "TWMessageBarManager").

最简单的方法就是,将这个 TWMessageBarManager 拖入到你的工程项目当中。当然,拖进工程之后,你也需要看看里面文件的一些描述信息。

Usage

Calling the manager

调用这个控制器

As a singleton class, the manager can be accessed from anywhere within your app via the + sharedInstancefunction:

因为他是一个单例,所以,你可以在你的应用程序的任何地方,通过方法 sharedInstance 来调用:

[TWMessageBarManager sharedInstance]

Presenting a basic message

展示一条基本的信息

All messages can be preseted via showMessageWithTitle:description:type:. Additional arguments include duration and callback blocks to be notified of a user tap.

所有的信息都可以通过showMessageWithTitle:description:type:来展示出来,额外的一些参数包括,显示时长,用户点击提示的回调。

Basic message:

基本信息:

[[TWMessageBarManager sharedInstance] showMessageWithTitle:@"Account Updated!"                                               description:@"Your account was successfully updated."                                                      type:TWMessageBarMessageTypeSuccess];

The default display duration is 3 seconds. You can override this value by supplying an additional argument:

这个默认的显示时间是3s,当然啰,你也可以重写他嘛:

[[TWMessageBarManager sharedInstance] showMessageWithTitle:@"Account Updated!"                                               description:@"Your account was successfully updated."                                                      type:TWMessageBarMessageTypeSuccess                                               forDuration:6.0];

Hiding messages

隐藏信息

It's not currently possible to hide or cancel a message on a per-instance basis. Instead, all messages must be canceled at once. This action may or may not be animated:

不大可能立刻为每一个基础信息展示隐藏或者取消掉。相对的,要取消也是所有的信息一起取消,而且是立刻,下面的方法有两种,一种是有动画的取消,一种是没有动画的取消:

[[TWMessageBarManager sharedInstance] hideAllAnimated:YES]; // animated[[TWMessageBarManager sharedInstance] hideAll]; // non-animated

Callbacks

回调

By default, if a user taps on a message while it is presented, it will automatically dismiss. To be notified of the touch, simply supply a callback block:

默认的,当用户点击到了这条展示的信息,他将会自动消失掉,为了标记这次点击,简单的从一个回调的block中取点击事件就可以了:

[[TWMessageBarManager sharedInstance] showMessageWithTitle:@"Account Updated!"                                               description:@"Your account was successfully updated."                                                      type:TWMessageBarMessageTypeSuccess callback:^{                                                          NSLog(@"Message bar tapped!");}];

Queue

队列

The manager is backed by a queue that can handle an infinite number of sequential requests. You can stack as many messages you want on the stack and they will be presetented one after another:

这个控制器也是可以被存储在队列中的咯,这个队列会管理一系列的请求而挨个展示。你可以将你要展示的信息挨个的添加进这个队列中吧。

[[TWMessageBarManager sharedInstance] showMessageWithTitle:@"Message 1"                                               description:@"Description 1"                                                      type:TWMessageBarMessageTypeSuccess];[[TWMessageBarManager sharedInstance] showMessageWithTitle:@"Message 2"                                               description:@"Description 2"                                                      type:TWMessageBarMessageTypeError];[[TWMessageBarManager sharedInstance] showMessageWithTitle:@"Message 3"                                               description:@"Description 3"                                                      type:TWMessageBarMessageTypeInfo];

Customization

定制

An object conforming to the TWMessageBarStyleSheet protocol defines the message bar's look and feel:

一个遵守TWMessageBarStyleSheet 协议的对象定义了信息条的样式以及感觉:

+ (UIColor *)backgroundColorForMessageType:(TWMessageBarMessageType)type;+ (UIColor *)strokeColorForMessageType:(TWMessageBarMessageType)type;+ (UIImage *)iconImageForMessageType:(TWMessageBarMessageType)type;

If no style sheet is supplied, a default class is provided on initialization. To customize the look and feel of your message bars, simply supply an object conforming to the TWMessageBarStyleSheet protocol via:

如过你没有提供任何的设置样式,它会直接使用默认值。为了定制这个信息条的样式以及感觉,简单的提供一个与协议相关的对象进行一些配置。

@property (nonatomic, weak) id
styleSheet;

See TWAppDelegateDemoStyleSheet for an example on how to create a custom stylesheet.

怎么配置呢,不懂的话,请看看那个自定义的demo吧。

 

 

 

转载地址:http://nhjal.baihongyu.com/

你可能感兴趣的文章
后台 JavaScript 编译改进 Chrome 性能
查看>>
数据结构课程设计实战
查看>>
Rabbit.js —— 国产 RESTful 应用开发框架
查看>>
GitLab 9.3.0-rc2 发布,代码托管平台
查看>>
《Adobe Illustrator CC经典教程》—第0课0.8节创建和编辑渐变
查看>>
《Dreamweaver CS6完美网页制作——基础、实例与技巧从入门到精通》——第2章 网页色彩知识2.1 网页配色基础...
查看>>
物联网设备安全1.6 小结
查看>>
细数二十世纪最伟大的十大算法
查看>>
《机器学习与数据科学(基于R的统计学习方法)》——2.10 SQL数据库
查看>>
MySQL 中你应该使用什么数据类型表示时间?
查看>>
《Visual Basic 2012入门经典》----1.6 设计界面
查看>>
《易学C++(第2版)》——1.3 选好一种语言
查看>>
Java8中CAS的增强
查看>>
基本线程同步(四)在同步代码中使用条件
查看>>
高管必备思维:区分2类问题和4类可视化方法
查看>>
《C++ 黑客编程揭秘与防范(第2版)》——第6章 加密与解密
查看>>
《Visual C++ 开发从入门到精通》——2.4 输入/输出基础
查看>>
地平线谭洪贺:AI芯片怎么降功耗?从ISSCC2017说起
查看>>
《树莓派用户指南(第3版)》——第1篇 主板 第1章 初识树莓派 1.1 主板简介...
查看>>
MySQL · myrocks · fast data load
查看>>