Giter Club home page Giter Club logo

ebbannerview's Introduction

Swift beta version is now available! Swift README.md
Swift beta 版本现已推出! 中文 Swift README.md

查看中文文档 Chinese README.md

Email:[email protected]

微信:pikacode

EBBannerView

Only one line to show:

  • a banner the same style as iOS Push Notifications (auto show iOS 9~13 styles up to system version)

  • auto play a sound or vibrate when the banner is showing

  • support swipe down gesture for a long text

And more:

  • custom banner's icon/title/date/content/animation_time_interval

  • custom the sound (use system sound or play a sound file)

  • autosize portrait/landscape frame

  • show a custom view with different frame in portrait/landscape

  • custom view has different animation mode, appear from top/left/right/left/center

  • NSNotification with click event and pass a value

Screenshot

System style:

Custom style:

Installation

pod

target 'YourTargetName' do
  pod 'EBBannerView'
end

Usage

System style


#import <EBBannerView.h>

2 ways to use:

1.Show a iOS style banner with one line

up to system version,will show iOS 9~13 style,auto show app icon/name.

[EBBannerView showWithContent:@"custom content"];

2.Customize all values include iOS style

//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];
Parameters:

(if not set will use default values)

  • style:the iOS style, default is UIDevice.currentDevice.systemVersion.intValue, type enum : NSInteger {9/10/11}
  • icon:the icon, default is app icon, type UIImage
  • title:the title, default is app name, type NSString
  • date:the date, default is localized string @"现在" = @"now", type NSString
  • content:the content, type NSString
  • showAnimationDuration:the animation time(show the banner), type NSTimeInterval, default is 0.3
  • hideAnimationDuration:the animation time(hide the banner), type NSTimeInterval, default is 0.5
  • stayDuration:how long the banner will stay before hide, type NSTimeInterval, default is 4.0
  • swipeDownStayDuration:how long a long text banner will stay before hide when it is expanded, default is 4.0. U can set it a large value, then the banner will not hide, until customer click it or call 'hide'
  • object:you can set it when create, then get it when clicked by adding an observer (see below), default is content,type id
  • soundID:the sound will play when the banner is showing (when the mute is turn on iPhone will vibrate), type UInt32
    • it's iOS system sound id, default push notification sound "Tritone" is 1312

    • More sound id to see here iOS Predefined sounds or here AudioServices sounds

    • You can download all the system sounds UISounds.zip , listen and choose one which you perfer, then check out it's id with the form above

  • soundName:play a cusome sound file, type NSString
    • drag the file to Xcode proj
    • pass the file name and extension,e.g. banner.soundName = @"sound.mp3"
  • showDetailOrHideWhenClickLongText: when click a long text banner, expand it for all height or hide it, YES = expand/NO = hide, default is YES

Custom style


#import <EBCustomBannerView.h>

2 ways to use:

1.create and show immediately

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.create and show after

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];
Parameters:
  • portraitFrame: frame in portrait,default is view.frame,type CGRect
  • landscapeFrame: frame in landscape,default is view.frame,type CGRect
  • soundID: (the same as system style's)
  • soundName: (the same as system style's)
  • animationDuration: (the same as system style's)
  • stayDuration: (the same as system style's)
  • portraitMode: in portrait view appears from top/bottom/left/right/center, default is top, type enum
  • landscapeMode: in landscape view appears from top/bottom/left/right/center, default is top, type enum
  • centerModeDurations: the animation time of view appears from center, default is @[@0.3, @0.2, @0.1], animationDuration is invalid for center animation

Handle click event and pass value (system style)

  • add an observer for EBBannerViewDidClickNotification and handle click event
  • pass an object when init the banner, and get it when clicked
#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);
}

ebbannerview's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ebbannerview's Issues

iOS12崩溃-label:bug.

+(instancetype)bannerViewWithStyle:(EBBannerViewStyle)style{ __block EBBannerView *bannerView; [sharedBannerViews enumerateObjectsUsingBlock:^(EBBannerView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if (obj.maker.style == style) { bannerView = obj; } }]; if (bannerView == nil) { bannerView = [[NSBundle bundleForClass:self.class] loadNibNamed:@"EBBannerView" owner:nil options:nil][style-9]; [[NSNotificationCenter defaultCenter] addObserver:bannerView selector:@selector(applicationDidChangeStatusBarOrientationNotification) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; [bannerView addGestureRecognizer]; [sharedBannerViews addObject:bannerView]; } return bannerView; }

12 -9 崩溃

iOS 12 beta 闪退

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/eagle/Library/Developer/CoreSimulator/Devices/07D4020A-3F02-4401-8F6C-7CBE2F9CB6FB/data/Containers/Bundle/Application/66A18A55-B7B2-4483-9530-B03C9746EB2F/demo.app> (loaded)' with name 'EBBannerViewController''

适配iPhoneX

还没有适配iPhoneX,肯请大大早日适配

custom的使用问题

使用了最新版本,选择了custom style后,点击top,出现顶部banner。
再点击banner上的close按钮后,页面变得没有反应,应该是window的问题,还需要修改一下。

iOS14依然会崩溃哦

image

EBBannerView更新到1.1.2版本, 在应用内收到推送,过几秒种就仍然会崩溃,
从图片左边的调用栈看,一直调用
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
直至崩溃

iOS14崩溃

SEGV_ACCERR EBBannerWindow hitTest:withEvent:

建议

如果ios8系统加入此工程,推送的内容多行时,UI会有些错位
建议修改下计算行高的逻辑

请问如何清除全部通知???

你好,试以下方法,都无法清除通知栏显示的通知;
UIApplication.shared.cancelAllLocalNotifications()

也无法获取通知;
let locals = UIApplication.shared.scheduledLocalNotifications

// 使用代码
image

// 清除代码
image

iOS14崩溃问题修改建议

if (@available(iOS 13.0, *)) {
    NSEnumerator *frontToBackWindows = [UIApplication.sharedApplication.windows reverseObjectEnumerator];
    for (UIWindow *window in frontToBackWindows) {
        BOOL windowOnMainScreen = window.screen == UIScreen.mainScreen;
        BOOL windowIsVisible = !window.hidden && window.alpha > 0;
        BOOL windowLevelNormal = window.windowLevel == UIWindowLevelNormal;
        if (windowOnMainScreen && windowIsVisible && windowLevelNormal) {
            return [window hitTest:point withEvent:event];
            break;
        }
    }
// return [UIApplication.sharedApplication.keyWindow hitTest:point withEvent:event];
}

这样取最上层window而不是直接拿keyWindow.

xcode10.3 编译报错

EBBannerView.xib:-1: Failed to find or create execution context for description '<IBCocoaTouchPlatformToolDescription: 0x7fbbb197dc20> System content for IBCocoaTouchFramework-NineOneAndLater <IBScaleFactorDeviceTypeDescription: 0x7fbbb1990920> scaleFactor=2x'. These intermediate objects were non-nil: (

横竖屏问题

可否暴露一个支持横竖屏的方法,出现弹窗后页面状态栏就会滑动,但是需求不能滑

sharedWindow.m里面
[EBBannerViewController setSupportedInterfaceOrientations:UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape];
默认横竖屏都支持

怎么获取推送内容啊 make.content

上个版本还可以
[EBForeNotification handleRemoteNotification:userInfo soundID:1312]; 直接userInfo
现在
EBBannerView *banner = [EBBannerView bannerWithBlock:^(EBBannerViewMaker *make) {
make.style = EBBannerViewStyleiOS9;//指定系统样式,不指定自动依据系统显示不同样式
make.style = 9;//展示 iOS9 样式
make.content = @"MINE eye hath played the painter and hath stelled";
}];
怎么办啊

提几点优化建议

1、点击推送栏回调不友好(应该返回userinfo,由外部自己处理),不然通过 NSNotification 里拿到的只是 content,一点用也没有,谁也不会拿着 content 去做跳转的。那我也不想在弹出推送栏之前先使用成员变量把跳转进行保存,因为很有可能被后面来的推送给覆盖掉。
2、应该要支持下,当多个推送来时要怎么处理,是pendding住后面的推送还是忽略后面的推送。
3、既然iOS 10已经支持了,如果可以话可以把iOS10的部分封装到你的框架内部,这点你可以自己考虑是否合适,可能封装的工作量会增大很多。

状态条颜色修改不正确

我在demo里的SystemStyleViewController.m文件的viewDidLoad方法中加入下列代码
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
将状态条文字改为白色,在显示提示框后状态条文字颜色被修改为黑色

使用cocoapods导入项目会引起闪退

原因,在pods中的xib不是属于mainbundle的

修改:
EBBannerView.m 46行
NSBundle *bundle = [NSBundle bundleForClass:self.class];

EBBannerViewController.m 19行
NSBundle *bundle = [NSBundle bundleForClass:self.class];

可以解决

关于UIView animateWithDuration weakSelf的疑问

WEAK_SELF(weakSelf); CGFloat originHeight = self.contentLabel.frame.size.height; [UIView animateWithDuration:_maker.animationDuration animations:^{ weakSelf.frame = CGRectMake(weakSelf.fixedX, weakSelf.fixedY, weakSelf.fixedWidth, weakSelf.standardHeight + weakSelf.calculatedHeight - originHeight + 1); } completion:^(BOOL finished) { weakSelf.frame = CGRectMake(weakSelf.fixedX, weakSelf.fixedY, weakSelf.fixedWidth, weakSelf.standardHeight + weakSelf.calculatedHeight - originHeight + 1); }];
楼主你好,看到这里你写的weakSelf我想问下,为什么用weakSelf,这里应该并不具有循环强引用

在有UIAlertView弹出后,keyWindow会被替换为emptyWindow

在有UIAlertView弹出后,因为UIEmptywindow的alertLevel为2000,keyWindow会被替换为emptyWindow,这会导致项目中有[UIApplication sharedApplication].keywindow addsubView:xxView];的控件被添加到emptyWindow上,以至于这些控件无法交换和销毁。

Dark Mode Issue

I am not able to read contents when my phone is in dark mode

image

旧项目Xcode13无法显示

最近更新了xocde13 发现无法显示了 目前使用1.1.0版本,通过调试时发现keyWindow是没有大小的,目前我改变了下源码,暂时解决了显示问题
+(instancetype)sharedWindow{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedWindow = [UIApplication sharedApplication].delegate.window;
return sharedWindow;
}
项目中用到的功能不多目前解决了我的问题
同时非常感谢作者!!!

显示提示框后状态条文字颜色不正确

我在demo里的SystemStyleViewController.m文件的viewDidLoad方法中加入下列代码
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
将状态条文字改为白色,在显示提示框后状态条文字颜色被修改为黑色

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.