天天看點

使用開源庫 TWMessageBarManager 展示系統級别的通知TWMessageBarManager

使用開源庫 TWMessageBarManager 展示系統級别的通知TWMessageBarManager

簡單翻譯

<a href="https://github.com/terryworona/twmessagebarmanager" target="_blank">https://github.com/terryworona/twmessagebarmanager</a>

an ios manager for presenting system-wide notifications via a dropdown message bar.

一個ios的管理類,用來展示系統級别的通知,通過一個下拉的資訊條。

使用開源庫 TWMessageBarManager 展示系統級别的通知TWMessageBarManager

requires ios 6.0 or later

requires automatic reference counting (arc)

需要ios6.0或以上

需要arc

drop-in singleton manager supported across all devices.

simple to use protocols and callbacks.

landscape and portrait orientation support.

highly customizable.

單例模式,支援所有的種類的裝置

可以使用協定或者block

支援橫屏豎屏

高度定制

terry worona

推薦用cocopods來安裝吧。

simply add the following line to your <code>podfile</code>:

your podfile should look something like:

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 拖入到你的工程項目當中。當然,拖進工程之後,你也需要看看裡面檔案的一些描述資訊。

調用這個控制器

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

因為他是一個單例,是以,你可以在你的應用程式的任何地方,通過方法 sharedinstance 來調用:

展示一條基本的資訊

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:

基本資訊:

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

這個預設的顯示時間是3s,當然啰,你也可以重寫他嘛:

隐藏資訊

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:

不大可能立刻為每一個基礎資訊展示隐藏或者取消掉。相對的,要取消也是所有的資訊一起取消,而且是立刻,下面的方法有兩種,一種是有動畫的取消,一種是沒有動畫的取消:

回調

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中取點選事件就可以了:

隊列

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:

這個控制器也是可以被存儲在隊列中的咯,這個隊列會管理一系列的請求而挨個展示。你可以将你要展示的資訊挨個的添加進這個隊列中吧。

定制

an object conforming to the twmessagebarstylesheet protocol defines the message bar's look and feel:

一個遵守twmessagebarstylesheet 協定的對象定義了資訊條的樣式以及感覺:

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:

如過你沒有提供任何的設定樣式,它會直接使用預設值。為了定制這個資訊條的樣式以及感覺,簡單的提供一個與協定相關的對象進行一些配置。

see twappdelegatedemostylesheet for an example on how to create a custom stylesheet.

怎麼配置呢,不懂的話,請看看那個自定義的demo吧。