Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e7d66aefe3 | |||
| 7eb79da4f0 | |||
| 0c103128dd | |||
| fac5c91daa | |||
| 5c949092f5 | |||
| cdc51f3243 | |||
| 7d1890f7c5 | |||
| 26d6eda4f5 | |||
| 9dfcc29703 | |||
| 6d00f770ef | |||
| 23a64f768d | |||
| e3fd1677b1 | |||
| dfbb1ed5f6 | |||
| 71aec53e1d | |||
| a24706854d |
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "CWStatusBarNotification"
|
||||
s.version = "2.3.0"
|
||||
s.version = "2.3.4"
|
||||
s.summary = "A library that creates status bar notifications."
|
||||
s.description = "CWStatusBarNotification is a library allows you to present a beautiful text-based notification in the status bar."
|
||||
s.homepage = "https://github.com/cezarywojcik/CWStatusBarNotification"
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
// Copyright (c) 2015 Cezary Wojcik. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
/**
|
||||
* @brief A simple completion used for handling tapping the notification.
|
||||
*/
|
||||
@@ -20,6 +18,10 @@ typedef void(^CWCompletionBlock)(void);
|
||||
* label.
|
||||
*/
|
||||
@interface ScrollLabel : UILabel
|
||||
/**
|
||||
* Used to find the amount of time that the label will spend scrolling.
|
||||
* @return The amount of time that will be spent scrolling.
|
||||
*/
|
||||
- (CGFloat)scrollTime;
|
||||
@end
|
||||
|
||||
@@ -141,10 +143,16 @@ typedef NS_ENUM(NSInteger, CWNotificationAnimationType) {
|
||||
*/
|
||||
@property (assign, nonatomic) BOOL multiline;
|
||||
/**
|
||||
* The supported interface orientations. Default value is
|
||||
* @c UIInterfaceOrientationMaskAll.
|
||||
* The supported interface orientations. Default value is the
|
||||
* @c supportedInterfaceOrientations value of the root view controller of the
|
||||
* application.
|
||||
*/
|
||||
@property (nonatomic) UIInterfaceOrientationMask supportedInterfaceOrientations;
|
||||
/**
|
||||
* The amount of time that it takes to animate the notification in or out.
|
||||
* Default value is 0.25.
|
||||
*/
|
||||
@property (nonatomic) NSTimeInterval notificationAnimationDuration;
|
||||
/**
|
||||
* Determines whether the notification covers the status bar or both the status
|
||||
* bar and the navigation bar. Default value is
|
||||
@@ -196,7 +204,7 @@ typedef NS_ENUM(NSInteger, CWNotificationAnimationType) {
|
||||
* not including the animate in and out times.
|
||||
*/
|
||||
- (void)displayNotificationWithMessage:(NSString *)message
|
||||
forDuration:(CGFloat)duration;
|
||||
forDuration:(NSTimeInterval)duration;
|
||||
|
||||
/**
|
||||
* Displays a notification with the indicated attributed string and then
|
||||
@@ -221,7 +229,7 @@ typedef NS_ENUM(NSInteger, CWNotificationAnimationType) {
|
||||
*/
|
||||
- (void)displayNotificationWithAttributedString:(NSAttributedString *)
|
||||
attributedString
|
||||
forDuration:(CGFloat)duration;
|
||||
forDuration:(NSTimeInterval)duration;
|
||||
|
||||
/**
|
||||
* Displays a notification with the indicated custom view and then performs the
|
||||
@@ -245,7 +253,7 @@ typedef NS_ENUM(NSInteger, CWNotificationAnimationType) {
|
||||
* not including the animate in and out times.
|
||||
*/
|
||||
- (void)displayNotificationWithView:(UIView *)view
|
||||
forDuration:(CGFloat)duration;
|
||||
forDuration:(NSTimeInterval)duration;
|
||||
|
||||
/**
|
||||
* Dismisses the currently presented notification and then performs the
|
||||
|
||||
@@ -11,13 +11,11 @@
|
||||
|
||||
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
|
||||
|
||||
#define STATUS_BAR_ANIMATION_LENGTH 0.25f
|
||||
#define FONT_SIZE 12.0f
|
||||
#define PADDING 10.0f
|
||||
#define SCROLL_SPEED 40.0f
|
||||
#define SCROLL_DELAY 1.0f
|
||||
|
||||
|
||||
# pragma mark - ScrollLabel
|
||||
|
||||
@implementation ScrollLabel
|
||||
@@ -196,13 +194,18 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
self = [super init];
|
||||
if (self) {
|
||||
// set default
|
||||
self.notificationLabelBackgroundColor = [[UIApplication sharedApplication] delegate].window.tintColor;
|
||||
if ([[[UIApplication sharedApplication] delegate] respondsToSelector:@selector(window)]) {
|
||||
self.notificationLabelBackgroundColor = [[UIApplication sharedApplication] delegate].window.tintColor;
|
||||
} else {
|
||||
self.notificationLabelBackgroundColor = [UIColor blackColor];
|
||||
}
|
||||
self.notificationLabelTextColor = [UIColor whiteColor];
|
||||
self.notificationLabelFont = [UIFont systemFontOfSize:FONT_SIZE];
|
||||
self.notificationLabelHeight = 0.0;
|
||||
self.customView = nil;
|
||||
self.multiline = NO;
|
||||
self.supportedInterfaceOrientations = UIInterfaceOrientationMaskAll;
|
||||
self.supportedInterfaceOrientations = [UIApplication sharedApplication].keyWindow.rootViewController.supportedInterfaceOrientations;
|
||||
self.notificationAnimationDuration = 0.25;
|
||||
self.notificationStyle = CWNotificationStyleStatusBarNotification;
|
||||
self.notificationAnimationInStyle = CWNotificationAnimationStyleBottom;
|
||||
self.notificationAnimationOutStyle = CWNotificationAnimationStyleBottom;
|
||||
@@ -245,7 +248,7 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
if (SYSTEM_VERSION_LESS_THAN(@"8.0") && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
|
||||
return [UIScreen mainScreen].bounds.size.height;
|
||||
}
|
||||
return [UIScreen mainScreen].bounds.size.width;
|
||||
return [[UIApplication sharedApplication] keyWindow].bounds.size.width;
|
||||
}
|
||||
|
||||
- (CGFloat)getStatusBarOffset
|
||||
@@ -256,6 +259,27 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
- (CGFloat)getNavigationBarHeight
|
||||
{
|
||||
if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ||
|
||||
UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
||||
return 44.0f;
|
||||
}
|
||||
return 30.0f;
|
||||
}
|
||||
|
||||
- (CGFloat)getNotificationLabelHeight
|
||||
{
|
||||
switch (self.notificationStyle) {
|
||||
case CWNotificationStyleStatusBarNotification:
|
||||
return [self getStatusBarHeight];
|
||||
case CWNotificationStyleNavigationBarNotification:
|
||||
return [self getStatusBarHeight] + [self getNavigationBarHeight];
|
||||
default:
|
||||
return [self getStatusBarHeight];
|
||||
}
|
||||
}
|
||||
|
||||
- (CGRect)getNotificationLabelTopFrame
|
||||
{
|
||||
return CGRectMake(0, [self getStatusBarOffset] + -1*[self getNotificationLabelHeight], [self getStatusBarWidth], [self getNotificationLabelHeight]);
|
||||
@@ -281,27 +305,6 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
return CGRectMake(0, [self getStatusBarOffset], [self getStatusBarWidth], [self getNotificationLabelHeight]);
|
||||
}
|
||||
|
||||
- (CGFloat)getNavigationBarHeight
|
||||
{
|
||||
if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ||
|
||||
UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
||||
return 44.0f;
|
||||
}
|
||||
return 30.0f;
|
||||
}
|
||||
|
||||
- (CGFloat)getNotificationLabelHeight
|
||||
{
|
||||
switch (self.notificationStyle) {
|
||||
case CWNotificationStyleStatusBarNotification:
|
||||
return [self getStatusBarHeight];
|
||||
case CWNotificationStyleNavigationBarNotification:
|
||||
return [self getStatusBarHeight] + [self getNavigationBarHeight];
|
||||
default:
|
||||
return [self getStatusBarHeight];
|
||||
}
|
||||
}
|
||||
|
||||
# pragma mark - screen orientation change
|
||||
|
||||
- (void)updateStatusBarFrame
|
||||
@@ -361,7 +364,7 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
[view setTranslatesAutoresizingMaskIntoConstraints:NO];
|
||||
[self.customView addSubview:view];
|
||||
|
||||
// Setup Auto Layout constaints so that the custom view that is added is constained to be the same
|
||||
// Setup Auto Layout constaints so that the custom view that is added is consrtained to be the same
|
||||
// size as its superview, whose frame will be altered
|
||||
[self.customView addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.customView attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0]];
|
||||
[self.customView addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.customView attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0]];
|
||||
@@ -373,7 +376,7 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
|
||||
- (void)createNotificationWindow
|
||||
{
|
||||
self.notificationWindow = [[CWWindowContainer alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
||||
self.notificationWindow = [[CWWindowContainer alloc] initWithFrame:[[[UIApplication sharedApplication] keyWindow] bounds]];
|
||||
self.notificationWindow.backgroundColor = [UIColor clearColor];
|
||||
self.notificationWindow.userInteractionEnabled = YES;
|
||||
self.notificationWindow.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
@@ -489,7 +492,7 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateStatusBarFrame) name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
|
||||
|
||||
// animate
|
||||
[UIView animateWithDuration:STATUS_BAR_ANIMATION_LENGTH animations:^{
|
||||
[UIView animateWithDuration:self.notificationAnimationDuration animations:^{
|
||||
[self firstFrameChange];
|
||||
} completion:^(BOOL finished) {
|
||||
double delayInSeconds = [self.notificationLabel scrollTime];
|
||||
@@ -500,7 +503,7 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
}
|
||||
}
|
||||
|
||||
- (void)displayNotificationWithMessage:(NSString *)message forDuration:(CGFloat)duration
|
||||
- (void)displayNotificationWithMessage:(NSString *)message forDuration:(NSTimeInterval)duration
|
||||
{
|
||||
[self displayNotificationWithMessage:message completion:^{
|
||||
self.dismissHandle = perform_block_after_delay(duration, ^{
|
||||
@@ -515,7 +518,7 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
[[self notificationLabel] setAttributedText:attributedString];
|
||||
}
|
||||
|
||||
- (void)displayNotificationWithAttributedString:(NSAttributedString *)attributedString forDuration:(CGFloat)duration
|
||||
- (void)displayNotificationWithAttributedString:(NSAttributedString *)attributedString forDuration:(NSTimeInterval)duration
|
||||
{
|
||||
[self displayNotificationWithMessage:[attributedString string] forDuration:duration];
|
||||
[[self notificationLabel] setAttributedText:attributedString];
|
||||
@@ -527,7 +530,7 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
self.isCustomView = YES;
|
||||
self.notificationIsShowing = YES;
|
||||
|
||||
// create UIWindow
|
||||
// create window
|
||||
[self createNotificationWindow];
|
||||
|
||||
// setup view
|
||||
@@ -549,7 +552,7 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateStatusBarFrame) name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
|
||||
|
||||
// animate
|
||||
[UIView animateWithDuration:STATUS_BAR_ANIMATION_LENGTH animations:^{
|
||||
[UIView animateWithDuration:self.notificationAnimationDuration animations:^{
|
||||
[self firstFrameChange];
|
||||
} completion:^(BOOL finished) {
|
||||
[completion invoke];
|
||||
@@ -557,7 +560,7 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
}
|
||||
}
|
||||
|
||||
- (void)displayNotificationWithView:(UIView *)view forDuration:(CGFloat)duration
|
||||
- (void)displayNotificationWithView:(UIView *)view forDuration:(NSTimeInterval)duration
|
||||
{
|
||||
[self displayNotificationWithView:view completion:^{
|
||||
self.dismissHandle = perform_block_after_delay(duration, ^{
|
||||
@@ -572,7 +575,7 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
cancel_delayed_block(self.dismissHandle);
|
||||
self.notificationIsDismissing = YES;
|
||||
[self secondFrameChange];
|
||||
[UIView animateWithDuration:STATUS_BAR_ANIMATION_LENGTH animations:^{
|
||||
[UIView animateWithDuration:self.notificationAnimationDuration animations:^{
|
||||
[self thirdFrameChange];
|
||||
} completion:^(BOOL finished) {
|
||||
UIView *view = self.isCustomView ? self.customView : self.notificationLabel;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Cezary Wojcik <http://www.cezarywojcik.com>
|
||||
Copyright (c) 2015 Cezary Wojcik <http://www.cezarywojcik.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
|
||||
[](https://travis-ci.org/cezarywojcik/CWStatusBarNotification)
|
||||
|
||||
**NOTE:** You can find a `Swift` implementation of this library [in the swift branch of this repo](https://github.com/cezarywojcik/CWStatusBarNotification/tree/swift).
|
||||
**NOTE:** You can find a **Swift 2.0** implementation of this library [in the swift branch of this repo](https://github.com/cezarywojcik/CWStatusBarNotification/tree/swift).
|
||||
|
||||
`CWStatusBarNotification` is a library that allows you to easily create text-based notifications that appear on the status bar.
|
||||
|
||||
You can find the documentation [here](http://cocoadocs.org/docsets/CWStatusBarNotification/).
|
||||
|
||||

|
||||
|
||||
## Requirements
|
||||
@@ -18,7 +20,7 @@ Works for iPhone and iPad.
|
||||
|
||||
### CocoaPods
|
||||
|
||||
`pod 'CWStatusBarNotification', '~> 2.3.0'`
|
||||
`pod 'CWStatusBarNotification', '~> 2.3.4'`
|
||||
|
||||
### Manual
|
||||
|
||||
@@ -140,17 +142,18 @@ The notifications will work in both screen orientations, however, screen rotatio
|
||||
|
||||
## Apps Using This Library
|
||||
|
||||
If you would like for your app to be featured here, [contact me](cezarywojcik.com/contact) and I would love to hear about your app!
|
||||
If you would like for your app to be featured here, [contact me](http://cezarywojcik.com/contact) and I would love to hear about your app!
|
||||
|
||||
* [SlideShare Presentations](https://itunes.apple.com/app/id917418728)
|
||||
* [Pong Ping](https://itunes.apple.com/us/app/pong-ping-social-addictive/id822887888)
|
||||
* [SlideShare Presentations](https://itunes.apple.com/app/id917418728)
|
||||
* [Pong Ping](https://itunes.apple.com/us/app/pong-ping-social-addictive/id822887888)
|
||||
* [NextMovies](https://itunes.apple.com/us/app/nextmovies-smart-movie-recommendation/id680850329)
|
||||
* [Social Dummy](https://itunes.apple.com/gb/app/social-dummy-create-fake-social/id610088272)
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Cezary Wojcik <http://www.cezarywojcik.com>
|
||||
Copyright (c) 2015 Cezary Wojcik <http://www.cezarywojcik.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
Reference in New Issue
Block a user