RGNotification 0.0.9

RGNotification 0.0.9

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布上次发布2014年12月

Robert Grzesik 维护。



  • Robert Grzesik

CRToast

CRToast 是一个库,它可以轻松创建显示在状态栏或导航栏上方或旁侧的通知。 CRToast最初基于 CWStatusBarNotification 开发。

demo

需求

CRToast 使用 ARC 并需要 iOS 7.0+。适用于 iPhone 和 iPad。

安装

手动安装

将文件夹 CRToast 复制到您的项目中。

使用方法

可以通过 CRToastManagershowNotificationWithOptions:completionBlock: 创建通知。这将根据指定的选项排队一个通知。您使用包含在 CRToast.h 中的键在字典中提供您的通知选项

示例

此代码

NSDictionary *options = @{
                          kCRToastTextKey : @"Hello World!",
                          kCRToastTextAlignmentKey : @(NSTextAlignmentCenter),
                          kCRToastBackgroundColorKey : [UIColor redColor],
                          kCRToastAnimationInTypeKey : @(CRToastAnimationTypeGravity),
                          kCRToastAnimationOutTypeKey : @(CRToastAnimationTypeGravity),
                          kCRToastAnimationInDirectionKey : @(CRToastAnimationDirectionLeft),
                          kCRToastAnimationOutDirectionKey : @(CRToastAnimationDirectionRight)
                          };
[CRToastManager showNotificationWithOptions:options
                            completionBlock:^{
                                NSLog(@"Completed");
                            }];

生成以下内容

自定义

CRToast 非常可自定义。借鉴了 UIStringDrawingdrawInRect:withAttributes: 方法,通知通过填充所有选项的字典来创建。

自定义外观

CRToast 允许设置以下内容

  • 左对齐的图片

包含以下内容的标题和子标题文本:

  • 文本颜色
  • 文本字体
  • 文本对齐方式
  • 文本颜色
  • 文本阴影颜色
  • 文本阴影偏移量
  • 文本最大行数

自定义动画

CRToast 还允许自定义动画。包括以下内容:

  • 动画类型(线性、弹簧或重力)
  • 动画物理系数(弹簧阻尼、弹簧初始速度、重力强度)
  • 展示类型(滑过工具条或推内容出去)
  • 状态栏可见性(状态栏在上还是在下)
  • 方向(进入和退出的任何方向)
  • 进入、保持在屏幕上和退出的时间

触摸交互

CRToast 允许通知响应不同类型的触摸交互(点击、滑动)。交互响应者可以设置为默认值或在每个通知的基础上设置。您可以设置的响应交互类型有

CRToastInteractionTypeSwipeUp          
CRToastInteractionTypeSwipeLeft        
CRToastInteractionTypeSwipeDown        
CRToastInteractionTypeSwipeRight       
CRToastInteractionTypeTapOnce          
CRToastInteractionTypeTapTwice         
CRToastInteractionTypeTwoFingerTapOnce 
CRToastInteractionTypeTwoFingerTapTwice              

还有通配符交互类型,它们覆盖了多种交互

CRToastInteractionTypeSwipe
CRToastInteractionTypeTap
CRToastInteractionTypeAll

可以使用以下构造函数使用 CRToastInteractionResponder 来响应任何交互

+ (instancetype)interactionResponderWithInteractionType:(CRToastInteractionType)interactionType
                                   automaticallyDismiss:(BOOL)automaticallyDismiss
                                                  block:(void (^)(CRToastInteractionType interactionType))block;

您可以将 CRToastInteractionResponder 的集合设置为目标,键为 kCRToastInteractionRespondersKey,在默认设置中有所有通知响应某特定的交互,或者在任何给定的通知中使交互响应者仅适用于该通知。

持久和程序性 dismiss 的通知

您还可以随时使用以下代码 dismiss 当前通知

+ (void)dismissNotification:(BOOL)animated;

您可以提供必须由用户 dismiss 的通知,通过传递 @(DBL_MAX) 作为 kCRToastTimeIntervalKey 的值,并设置将 dismiss 通知的交互响应者。

设置默认值

所有属性都已设置了合理的默认值,但是您可以使用 CRToastManagerssetDefaultOptions: 为应用程序的通知设置一组默认选项。

许可

The MIT License (MIT)

Copyright (c) 2013 Collin Ruffenach

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.