CRToast 0.0.9

CRToast 0.0.9

测试测试过的
语言语言 Obj-CObjective C
许可证 MIT
发布最新发布2015年10月

Ashton Williams维护。



CRToast 0.0.9

  • Collin Ruffenach和Ashton Williams

CRToast是一个库,可以轻松创建顶部或通过推挤状态栏或导航栏出现的通知。CRToast最初基于CWStatusBarNotification

demo

要求

CRToast使用ARC并且需要iOS 7.0以上。适用于iPhone和iPad。

安装

手动

将项目或源文件添加到您的项目中。

使用方法

可以通过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的键,使得所有通知都响应某种交互,或者对任何一个指定的通知,让交互响应者只为该通知工作。

持久化和程序性关闭通知

您还可以在任何时候使用以下方法关闭当前通知:

+ (void)dismissNotification:(BOOL)animated;

要呈现用户必须关闭的通知,可以将kCRToastTimeIntervalKey的值通过@(DBL_MAX)传递,并设置一个将关闭通知的交互响应者。

设置默认值

所有属性都设置了合理的默认值,但您可以使用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.