查看中文文档 Chinese README.md
Email:[email protected]
微信:pikacode
EBBannerView
只有一行可以显示
-
一个和 iOS 推送通知样式相同的横幅(自动显示 iOS 9~13 系统版本的样式)
-
横幅显示时自动播放声音或震动
-
支持长文本的向下滑动手势
还有更多:
-
自定义横幅的图标/标题/日期/内容/动画时间间隔
-
自定义声音(使用系统声音或播放声音文件)
-
自动调整横幅的横幅/竖幅框架
-
以不同的框架显示自定义视图
-
自定义视图有不同的动画模式,自上/左/右/左/中心出现
-
NSNotification 与点击事件和传递值
截图
系统样式
自定义样式
安装
Pod
target 'YourTargetName' do
pod 'EBBannerView'
end
用法
系统样式
#import <EBBannerView.h>
两种使用方式
1.显示带有单行的iOS样式横幅
支持系统版本:iOS 9~13,自动显示应用图标/名称。
[EBBannerView showWithContent:@"custom content"];
2.自定义所有值(包括iOS样式)
//1.create a banner, custom all values
EBBannerView *banner = [EBBannerView bannerWithBlock:^(EBBannerViewMaker *make) {
make.style = EBBannerViewStyleiOS9;//custom system, default is current
//make.style = 9;
make.content = @"MINE eye hath played the painter and hath stelled";
//make.object = ...
//make.icon = ...
//make.title = ...
//make.soundID = ...
}];
//2.show
[banner show];
参数
(如未设置,则使用默认值)
-
style
:iOS 风格,默认为UIDevice.currentDevice.systemVersion.intValue
,类型枚举 : NSInteger {9/10/11} -
icon
:图标,默认为应用图标,类型 UIImage -
title
:标题,默认为应用名称,类型 NSString -
date
:日期,默认为本地化字符串 @"现在" = @"now",类型 NSString -
content
:内容,类型 NSString -
showAnimationDuration
:动画时间(显示横幅),类型 NSTimeInterval,默认为 0.3 -
hideAnimationDuration
:动画时间(隐藏横幅),类型 NSTimeInterval,默认为 0.5 -
stayDuration
:横幅显示的持续时间,类型 NSTimeInterval,默认为 4.0 -
swipeDownStayDuration
:长文本横幅在展开后持续显示的时长,默认为 4.0。您可以设置一个较大的值,然后横幅将不会隐藏,直到用户点击它或调用 'hide' 方法 -
object
:创建时可以设置,点击时通过添加观察者获得(见下方),默认为content
,类型 id -
soundID
:横幅显示时播放的声音(当iPhone的静音开关开启时将振动),类型 UInt32-
它是 iOS 系统声音 ID,默认推送通知声音 "Tritone" 是 1312
-
更多声音 ID 请见此处 iOS 预定义声音 或此处 AudioServices 声音
-
您可以下载所有系统声音 UISounds.zip,试听并选择一个您喜欢的,然后检查它以上的
id
-
-
soundName
:播放自定义声音文件,类型 NSString- 将文件拖到 Xcode 项目中
- 传递文件名和扩展名,例如
banner.soundName = @"sound.mp3"
-
showDetailOrHideWhenClickLongText
:点击长文本横幅时,是展开全部高度还是隐藏,YES = 展开/NO = 隐藏,默认为 YES
自定义样式
#import <EBCustomBannerView.h>
两种使用方式
1.立即创建和显示
UIView *view = ...;//the view want to show
[EBCustomBannerView showCustomView:view block:^(EBCustomBannerViewMaker *make) {
make.portraitFrame = ...;//frame in portrait
make.portraitMode = EBCustomViewAppearModeTop;//appear from top in portrait
make.soundID = 1312;
make.stayDuration = 3.0;
//......
}];
2.创建后显示
UIView *view = ...;//the view want to show
//1.
EBCustomBannerView *customView = [EBCustomBannerView customView:view block:^(EBCustomBannerViewMaker *make) {
make.portraitFrame = ...;
make.portraitMode = EBCustomViewAppearModeTop;
make.soundID = 1312;
make.stayDuration = 3.0;
//......
}];
//2.
[customView show];
//[customView hide];
参数
portraitFrame
:纵向框架,默认是view.frame,类型为CGRectlandscapeFrame
:横向框架,默认是view.frame,类型为CGRectsoundID
:(与system style
相同)soundName
:(与system style
相同)animationDuration
:(与system style
相同)stayDuration
:(与system style
相同)portraitMode
:在纵向视图中从顶部/底部/左侧/右侧/中心出现,默认顶部,类型是枚举landscapeMode
:在横向视图中从顶部/底部/左侧/右侧/中心出现,默认顶部,类型是枚举centerModeDurations
:视图从中心出现的动画时间,默认是@[@0.3, @0.2, @0.1],中心动画时无效animationDuration
处理点击事件并传递系统样式值
- 为
EBBannerViewDidClickNotification
添加观察者,并处理点击事件 - 初始化横幅时传入一个对象,并在点击时获取它
#import <EBBannerView.h>
{
...
EBBannerView *banner = [EBBannerView bannerWithBlock:^(EBBannerViewMaker *make) {
...
make.object = aObject;
}];
}
{
...
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bannerViewDidClick:) name:EBBannerViewDidClickNotification object:nil];
}
-(void)bannerViewDidClick:(NSNotification*)noti{
NSLog(@"%@",noti.object);
}