测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布上次发布 | 2015年9月 |
由Maciej Gad维护。
依赖关系 | |
GKRToast | ~> 0.0.5 |
FLAnimatedImage | ~> 1.0 |
为iOS重放的Android Toast信息,易于定制的动画。
对于默认样式的Toast,只需写下
[GKRToast show:@"Your text"];
对于其他样式,请使用以下两个类之一 AIMToast
或 AIMFancyToast
,或创建自定义子类
AIMToast - 适用于All in Mobile的类,背景和文字颜色可以轻松自定义
如果您想制作带有自定义布局和动画的Toast,应该创建一个GKRToast
的子类,重写+ (GKRToastConfigure *)configure
方法,并返回Toast的新配置。例如,如果您想创建一个从左侧打开的Toast,您应该写出以下内容:
+ (GKRToastConfigure *)configure {
GKRToastConfigure *configure = [GKRToastConfigure new];
CGFloat offset = CGRectGetWidth([UIScreen mainScreen].bounds) * 0.5f + 100;
configure.animateShowLabel = ^(UIView *textContainer, UILabel *textLabel, MASConstraint *centerX, MASConstraint *centerY) {
centerX.offset = -offset;
[textContainer layoutIfNeeded];
centerX.offset = 0;
[UIView animateWithDuration:1.0f animations:^{
[textContainer layoutIfNeeded];
}];
};
return configure;
};
GKRToastConfigure
对象有以下属性:
属性 | 类型 | 描述 | 默认值 |
---|---|---|---|
backgroundView | UIView * | 全屏显示的背景 | 带有30%不透明度的背景颜色 |
textContainer | UIView * | 文本消息的容器 | 带有80%不透明度的背景颜色 |
textLabel | UILabel * | 显示消息文本的标签 | 白色文字颜色,行数设置为0 |
textEdgeInsets | UIEdgeInsets | textLabel 的边距 |
左、右、上和下设置为10 Pt |
hideTimeOut | NSTimeInterval | 显示时间(以秒为单位);如果设置为0,则永远不会自动隐藏 | 5s |
animateShowLabel | void(^)(UIView *textContainer, UILabel *textLabel, MASConstraint *centerX, MASConstraint *centerY) | 在将textContainer 添加到当前窗口后的block调用;centerX 和centerY 是为使Toast居中对屏幕设置约束的约束 |
0到1的alpha过渡在0.5秒内 |
animateShowBackground | void(^)(UIView *backgroundView) | 在将backgroundView 添加到当前窗口后的block调用 |
0到1的alpha过渡在0.5秒内 |
animateHideLabel | void(^)(UIView *textContainer, UILabel *textLabel, MASConstraint *centerX, MASConstraint *centerY) | 当需要在当前窗口中移除 textContainer 时进行块调用;动画结束后,请务必调用 [textLabel removeFromSuperview] 和 [textContainer removeFromSuperview] |
在 0.5 秒内从 1 到 0 的透明度过渡 |
animateHideBackground | void(^)(UIView *backgroundView) | 当需要在当前窗口中移除 backgroundView 时进行块调用;动画结束后,请务必调用 [backgroundView removeFromSuperview] |
在 0.5 秒内从 1 到 0 的透明度过渡 |