Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7eb79da4f0 | |||
| 0c103128dd | |||
| fac5c91daa | |||
| 5c949092f5 | |||
| cdc51f3243 | |||
| 7d1890f7c5 | |||
| 26d6eda4f5 | |||
| 9dfcc29703 | |||
| 6d00f770ef | |||
| 23a64f768d | |||
| e3fd1677b1 | |||
| dfbb1ed5f6 | |||
| 71aec53e1d | |||
| a24706854d | |||
| 9dd9bcecb2 | |||
| c5875f1311 | |||
| 6d2a139fa0 | |||
| 1a1d1c5d38 |
@@ -311,6 +311,7 @@
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
@@ -350,6 +351,7 @@
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "CWStatusBarNotification"
|
||||
s.version = "2.2.6"
|
||||
s.version = "2.3.3"
|
||||
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"
|
||||
|
||||
@@ -3,75 +3,270 @@
|
||||
// CWNotificationDemo
|
||||
//
|
||||
// Created by Cezary Wojcik on 11/15/13.
|
||||
// Copyright (c) 2013 Cezary Wojcik. All rights reserved.
|
||||
// Copyright (c) 2015 Cezary Wojcik. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
/**
|
||||
* @brief A simple completion used for handling tapping the notification.
|
||||
*/
|
||||
typedef void(^CWCompletionBlock)(void);
|
||||
|
||||
# pragma mark - ScrollLabel
|
||||
|
||||
/**
|
||||
* A subclass of @c UILabel that scrolls the text if it is too long for the
|
||||
* 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
|
||||
|
||||
# pragma mark - CWWindowContainer
|
||||
|
||||
/**
|
||||
* A subclass of @c UIWindow that overrides the @c hitTest method in order to
|
||||
* allow tap events to pass through the window.
|
||||
*/
|
||||
@interface CWWindowContainer : UIWindow
|
||||
|
||||
/// The height of the notification that is being displayed in the window.
|
||||
@property (assign, nonatomic) CGFloat notificationHeight;
|
||||
|
||||
@end
|
||||
|
||||
# pragma mark - CWViewController
|
||||
|
||||
/**
|
||||
* A subclass of @c UIViewController that allows handing over
|
||||
* @c supportedInterfaceOrientations if needed.
|
||||
*/
|
||||
@interface CWViewController : UIViewController
|
||||
/// Indicates the preferred status bar style.
|
||||
@property (nonatomic) UIStatusBarStyle preferredStatusBarStyle;
|
||||
@property (nonatomic, setter=setSupportedInterfaceOrientations:) NSInteger supportedInterfaceOrientations;
|
||||
/// Indicats the supported interface orientations.
|
||||
@property (nonatomic, setter=setSupportedInterfaceOrientations:)
|
||||
UIInterfaceOrientationMask supportedInterfaceOrientations;
|
||||
@end
|
||||
|
||||
# pragma mark - CWStatusBarNotification
|
||||
|
||||
/**
|
||||
* A subclass of @c NSObject that is responsible for managing status bar
|
||||
* notifications.
|
||||
*/
|
||||
@interface CWStatusBarNotification : NSObject
|
||||
|
||||
# pragma mark - enums
|
||||
|
||||
/**
|
||||
* @typedef CWNotificationStyle
|
||||
* @brief Determines the notification style.
|
||||
*/
|
||||
typedef NS_ENUM(NSInteger, CWNotificationStyle) {
|
||||
/// Covers the status bar portion of the screen.
|
||||
CWNotificationStyleStatusBarNotification,
|
||||
/// Covers the status bar and navigation bar portions of the screen.
|
||||
CWNotificationStyleNavigationBarNotification
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef CWNotificationAnimationStyle
|
||||
* @brief Determines the direction of animation for the notification.
|
||||
*/
|
||||
typedef NS_ENUM(NSInteger, CWNotificationAnimationStyle) {
|
||||
/// Animate in from the top or animate out to the top.
|
||||
CWNotificationAnimationStyleTop,
|
||||
/// Animate in from the bottom or animate out to the bottom.
|
||||
CWNotificationAnimationStyleBottom,
|
||||
/// Animate in from the left or animate out to the left.
|
||||
CWNotificationAnimationStyleLeft,
|
||||
/// Animate in from the right or animate out to the right.
|
||||
CWNotificationAnimationStyleRight
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef CWNotificationAnimationType
|
||||
* @brief Determines whether the notification moves the existing content out of
|
||||
* the way or simply overlays it.
|
||||
*/
|
||||
typedef NS_ENUM(NSInteger, CWNotificationAnimationType) {
|
||||
/// Moves existing content out of the way.
|
||||
CWNotificationAnimationTypeReplace,
|
||||
/// Overlays existing content.
|
||||
CWNotificationAnimationTypeOverlay
|
||||
};
|
||||
|
||||
# pragma mark - properties
|
||||
|
||||
/// The label that holds the notification text.
|
||||
@property (strong, nonatomic) ScrollLabel *notificationLabel;
|
||||
@property (strong, nonatomic) UIColor *notificationLabelBackgroundColor;
|
||||
@property (strong, nonatomic) UIColor *notificationLabelTextColor;
|
||||
@property (strong, nonatomic) UIFont *notificationLabelFont;
|
||||
@property (assign, nonatomic) CGFloat notificationLabelHeight;
|
||||
@property (strong, nonatomic) UIView *customView;
|
||||
@property (assign, nonatomic) BOOL multiline;
|
||||
|
||||
/// The @c UIView that holds a screenshot of the status bar view.
|
||||
@property (strong, nonatomic) UIView *statusBarView;
|
||||
|
||||
/// The block that gets triggered when the notification is tapped.
|
||||
@property (copy, nonatomic) CWCompletionBlock notificationTappedBlock;
|
||||
|
||||
@property (nonatomic) CWNotificationStyle notificationStyle;
|
||||
@property (nonatomic) NSInteger supportedInterfaceOrientations;
|
||||
@property (nonatomic) CWNotificationAnimationStyle notificationAnimationInStyle;
|
||||
@property (nonatomic) CWNotificationAnimationStyle notificationAnimationOutStyle;
|
||||
@property (nonatomic) CWNotificationAnimationType notificationAnimationType;
|
||||
/// Indicates whether the notification is currently being shown.
|
||||
@property (nonatomic) BOOL notificationIsShowing;
|
||||
/// Indicates whether the notification is currently dismissing.
|
||||
@property (nonatomic) BOOL notificationIsDismissing;
|
||||
|
||||
/// The window that holds the notification.
|
||||
@property (strong, nonatomic) CWWindowContainer *notificationWindow;
|
||||
|
||||
/**
|
||||
* The background color of the notification label. Default value is the tint
|
||||
* color of the application's main window.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *notificationLabelBackgroundColor;
|
||||
/**
|
||||
* The text color of the notification label. Default value is white.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *notificationLabelTextColor;
|
||||
/**
|
||||
* The font of the notification label. Default value is system font.
|
||||
*/
|
||||
@property (strong, nonatomic) UIFont *notificationLabelFont;
|
||||
/**
|
||||
* Allows setting a custom height for the notification label. If this value is
|
||||
* 0, the height will be determined by the @c notificationStyle. Default value
|
||||
* is 0.
|
||||
*/
|
||||
@property (assign, nonatomic) CGFloat notificationLabelHeight;
|
||||
/**
|
||||
* The custom view to present if using @c displayNotificationWithView. Default
|
||||
* value is @c nil.
|
||||
*/
|
||||
@property (strong, nonatomic) UIView *customView;
|
||||
/**
|
||||
* Determines whether the notification text has multiple lines. Default value is
|
||||
* @c NO.
|
||||
*/
|
||||
@property (assign, nonatomic) BOOL multiline;
|
||||
/**
|
||||
* 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
|
||||
* @c CWNotificationStyleStatusBarNotification.
|
||||
*/
|
||||
@property (nonatomic) CWNotificationStyle notificationStyle;
|
||||
/**
|
||||
* Determines the direction from which the notification animates in. Default
|
||||
* value is @c CWNotificationAnimationStyleBottom.
|
||||
*/
|
||||
@property (nonatomic) CWNotificationAnimationStyle notificationAnimationInStyle;
|
||||
/**
|
||||
* Determines the direction from which the notification animates out. Default
|
||||
* value is @c CWNotificationAnimationStyleBottom.
|
||||
*/
|
||||
@property (nonatomic) CWNotificationAnimationStyle
|
||||
notificationAnimationOutStyle;
|
||||
/**
|
||||
* Determines whether the the notification's animation replaces the existing
|
||||
* content or overlays it. Default value is
|
||||
* @c CWNotificationAnimationTypeReplace.
|
||||
*/
|
||||
@property (nonatomic) CWNotificationAnimationType notificationAnimationType;
|
||||
/**
|
||||
* The preferred status bar style. Default value is @c UIStatusBarStyleDefault.
|
||||
*/
|
||||
@property (nonatomic) UIStatusBarStyle preferredStatusBarStyle;
|
||||
|
||||
- (void)displayNotificationWithMessage:(NSString *)message forDuration:(CGFloat)duration;
|
||||
- (void)displayNotificationWithMessage:(NSString *)message completion:(void (^)(void))completion;
|
||||
- (void)displayNotificationWithView:(UIView *)view forDuration:(CGFloat)duration;
|
||||
- (void)displayNotificationWithView:(UIView *)view completion:(void (^)(void))completion;
|
||||
- (void)dismissNotification;
|
||||
#pragma mark - methods
|
||||
|
||||
/**
|
||||
* Displays a notification with the indicated message and then performs the
|
||||
* completion block once the notification animates in.
|
||||
* @param message
|
||||
* The content of the message to be displayed.
|
||||
* @param completion
|
||||
* The block to be invoked once the notification is displayed.
|
||||
*/
|
||||
- (void)displayNotificationWithMessage:(NSString *)message
|
||||
completion:(void (^)(void))completion;
|
||||
|
||||
/**
|
||||
* Displays a notification with the indicated message for the indicated
|
||||
* duration.
|
||||
* @param message
|
||||
* The content of the message to be displayed.
|
||||
* @param duration
|
||||
* The amount of seconds for which the notification should be displayed,
|
||||
* not including the animate in and out times.
|
||||
*/
|
||||
- (void)displayNotificationWithMessage:(NSString *)message
|
||||
forDuration:(NSTimeInterval)duration;
|
||||
|
||||
/**
|
||||
* Displays a notification with the indicated attributed string and then
|
||||
* performs the completion block once the notification animates in.
|
||||
* @param attributedString
|
||||
* The content of the message to be displayed.
|
||||
* @param completion
|
||||
* The block to be invoked once the notification is displayed.
|
||||
*/
|
||||
- (void)displayNotificationWithAttributedString:(NSAttributedString *)
|
||||
attributedString
|
||||
completion:(void (^)(void))completion;
|
||||
|
||||
/**
|
||||
* Displays a notification with the indicated message for the indicated
|
||||
* duration.
|
||||
* @param attributedString
|
||||
* The content of the message to be displayed.
|
||||
* @param duration
|
||||
* The amount of seconds for which the notification should be displayed,
|
||||
* not including the animate in and out times.
|
||||
*/
|
||||
- (void)displayNotificationWithAttributedString:(NSAttributedString *)
|
||||
attributedString
|
||||
forDuration:(NSTimeInterval)duration;
|
||||
|
||||
/**
|
||||
* Displays a notification with the indicated custom view and then performs the
|
||||
* completion block once the notification animates in.
|
||||
* @param view
|
||||
* The custom @c UIView that you wish to present.
|
||||
* @param completion
|
||||
* The block to be invoked once the notification is displayed.
|
||||
*/
|
||||
|
||||
- (void)displayNotificationWithView:(UIView *)view
|
||||
completion:(void (^)(void))completion;
|
||||
|
||||
/**
|
||||
* Displays a notification with the indicated custom view for the indicated
|
||||
* duration.
|
||||
* @param view
|
||||
* The custom @c UIView that you wish to present.
|
||||
* @param duration
|
||||
* The amount of seconds for which the notification should be displayed,
|
||||
* not including the animate in and out times.
|
||||
*/
|
||||
- (void)displayNotificationWithView:(UIView *)view
|
||||
forDuration:(NSTimeInterval)duration;
|
||||
|
||||
/**
|
||||
* Dismisses the currently presented notification and then performs the
|
||||
* completion block.
|
||||
* @param completion
|
||||
* The block to be invoked after the notification is dismissed.
|
||||
*/
|
||||
- (void)dismissNotificationWithCompletion:(void(^)(void))completion;
|
||||
|
||||
/**
|
||||
* Dismisses the currently presented notification.
|
||||
*/
|
||||
|
||||
- (void)dismissNotification;
|
||||
|
||||
@end
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// CWNotificationDemo
|
||||
//
|
||||
// Created by Cezary Wojcik on 11/15/13.
|
||||
// Copyright (c) 2013 Cezary Wojcik. All rights reserved.
|
||||
// Copyright (c) 2015 Cezary Wojcik. All rights reserved.
|
||||
//
|
||||
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
@@ -11,12 +11,72 @@
|
||||
|
||||
#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
|
||||
{
|
||||
UIImageView *textImage;
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
textImage = [[UIImageView alloc] init];
|
||||
[self addSubview:textImage];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (CGFloat)fullWidth
|
||||
{
|
||||
return [self.text sizeWithAttributes:@{NSFontAttributeName: self.font}].width;
|
||||
}
|
||||
|
||||
- (CGFloat)scrollOffset
|
||||
{
|
||||
if (self.numberOfLines != 1) return 0;
|
||||
|
||||
CGRect insetRect = CGRectInset(self.bounds, PADDING, 0);
|
||||
return MAX(0, [self fullWidth] - insetRect.size.width);
|
||||
}
|
||||
|
||||
- (CGFloat)scrollTime
|
||||
{
|
||||
return ([self scrollOffset] > 0) ? [self scrollOffset] / SCROLL_SPEED + SCROLL_DELAY : 0;
|
||||
}
|
||||
|
||||
- (void)drawTextInRect:(CGRect)rect
|
||||
{
|
||||
if ([self scrollOffset] > 0) {
|
||||
rect.size.width = [self fullWidth] + PADDING * 2;
|
||||
UIGraphicsBeginImageContextWithOptions(rect.size, NO, [UIScreen mainScreen].scale);
|
||||
[super drawTextInRect:rect];
|
||||
textImage.image = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
[textImage sizeToFit];
|
||||
[UIView animateWithDuration:[self scrollTime] - SCROLL_DELAY
|
||||
delay:SCROLL_DELAY
|
||||
options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut
|
||||
animations:^{
|
||||
textImage.transform = CGAffineTransformMakeTranslation(-[self scrollOffset], 0);
|
||||
} completion:^(BOOL finished) {
|
||||
}];
|
||||
} else {
|
||||
textImage.image = nil;
|
||||
[super drawTextInRect:CGRectInset(rect, PADDING, 0)];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
# pragma mark - CWWindowContainer
|
||||
|
||||
@implementation CWWindowContainer
|
||||
|
||||
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
|
||||
@@ -24,11 +84,9 @@
|
||||
CGFloat height;
|
||||
if (SYSTEM_VERSION_LESS_THAN(@"8.0") && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
|
||||
height = [UIApplication sharedApplication].statusBarFrame.size.width;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
height = [UIApplication sharedApplication].statusBarFrame.size.height;
|
||||
}
|
||||
|
||||
if (point.y > 0 && point.y < (self.notificationHeight != 0.0 ? self.notificationHeight : height)) {
|
||||
return [super hitTest:point withEvent:event];
|
||||
}
|
||||
@@ -38,6 +96,8 @@
|
||||
|
||||
@end
|
||||
|
||||
# pragma mark - CWViewController
|
||||
|
||||
@interface CWViewController()
|
||||
|
||||
@property (nonatomic, assign) NSInteger _cwViewControllerSupportedInterfaceOrientation;
|
||||
@@ -51,12 +111,12 @@
|
||||
return _preferredStatusBarStyle;
|
||||
}
|
||||
|
||||
- (void)setSupportedInterfaceOrientations:(NSInteger)supportedInterfaceOrientations
|
||||
- (void)setSupportedInterfaceOrientations:(UIInterfaceOrientationMask)supportedInterfaceOrientations
|
||||
{
|
||||
self._cwViewControllerSupportedInterfaceOrientation = supportedInterfaceOrientations;
|
||||
}
|
||||
|
||||
- (NSInteger)supportedInterfaceOrientations
|
||||
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
|
||||
{
|
||||
return self._cwViewControllerSupportedInterfaceOrientation;
|
||||
}
|
||||
@@ -111,66 +171,6 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
|
||||
delayedHandle(YES);
|
||||
}
|
||||
|
||||
# pragma mark - ScrollLabel
|
||||
|
||||
@implementation ScrollLabel
|
||||
{
|
||||
UIImageView *textImage;
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
textImage = [[UIImageView alloc] init];
|
||||
[self addSubview:textImage];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (CGFloat)fullWidth
|
||||
{
|
||||
return [self.text sizeWithAttributes:@{NSFontAttributeName: self.font}].width;
|
||||
}
|
||||
|
||||
- (CGFloat)scrollOffset
|
||||
{
|
||||
if (self.numberOfLines != 1) return 0;
|
||||
|
||||
CGRect insetRect = CGRectInset(self.bounds, PADDING, 0);
|
||||
return MAX(0, [self fullWidth] - insetRect.size.width);
|
||||
}
|
||||
|
||||
- (CGFloat)scrollTime
|
||||
{
|
||||
return ([self scrollOffset] > 0) ? [self scrollOffset] / SCROLL_SPEED + SCROLL_DELAY : 0;
|
||||
}
|
||||
|
||||
- (void)drawTextInRect:(CGRect)rect
|
||||
{
|
||||
if ([self scrollOffset] > 0) {
|
||||
rect.size.width = [self fullWidth] + PADDING * 2;
|
||||
UIGraphicsBeginImageContextWithOptions(rect.size, NO, [UIScreen mainScreen].scale);
|
||||
[super drawTextInRect:rect];
|
||||
textImage.image = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
[textImage sizeToFit];
|
||||
[UIView animateWithDuration:[self scrollTime] - SCROLL_DELAY
|
||||
delay:SCROLL_DELAY
|
||||
options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut
|
||||
animations:^{
|
||||
textImage.transform = CGAffineTransformMakeTranslation(-[self scrollOffset], 0);
|
||||
} completion:^(BOOL finished) {
|
||||
}];
|
||||
} else {
|
||||
textImage.image = nil;
|
||||
[super drawTextInRect:CGRectInset(rect, PADDING, 0)];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
# pragma mark - CWStatusBarNotification
|
||||
|
||||
@interface CWStatusBarNotification()
|
||||
@@ -193,10 +193,19 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
// set defaults
|
||||
self.notificationLabelBackgroundColor = [[UIApplication sharedApplication] delegate].window.tintColor;
|
||||
// set default
|
||||
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 = [UIApplication sharedApplication].keyWindow.rootViewController.supportedInterfaceOrientations;
|
||||
self.notificationAnimationDuration = 0.25;
|
||||
self.notificationStyle = CWNotificationStyleStatusBarNotification;
|
||||
self.notificationAnimationInStyle = CWNotificationAnimationStyleBottom;
|
||||
self.notificationAnimationOutStyle = CWNotificationAnimationStyleBottom;
|
||||
@@ -204,7 +213,6 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
self.notificationIsDismissing = NO;
|
||||
self.isCustomView = NO;
|
||||
self.preferredStatusBarStyle = UIStatusBarStyleDefault;
|
||||
self.supportedInterfaceOrientations = UIInterfaceOrientationMaskAll;
|
||||
|
||||
// create tap recognizer
|
||||
self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(notificationTapped:)];
|
||||
@@ -251,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]);
|
||||
@@ -276,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
|
||||
@@ -356,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]];
|
||||
@@ -484,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];
|
||||
@@ -495,13 +503,34 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
}
|
||||
}
|
||||
|
||||
- (void)displayNotificationWithMessage:(NSString *)message forDuration:(NSTimeInterval)duration
|
||||
{
|
||||
[self displayNotificationWithMessage:message completion:^{
|
||||
self.dismissHandle = perform_block_after_delay(duration, ^{
|
||||
[self dismissNotification];
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)displayNotificationWithAttributedString:(NSAttributedString *)attributedString completion:(void (^)(void))completion
|
||||
{
|
||||
[self displayNotificationWithMessage:[attributedString string] completion:completion];
|
||||
[[self notificationLabel] setAttributedText:attributedString];
|
||||
}
|
||||
|
||||
- (void)displayNotificationWithAttributedString:(NSAttributedString *)attributedString forDuration:(NSTimeInterval)duration
|
||||
{
|
||||
[self displayNotificationWithMessage:[attributedString string] forDuration:duration];
|
||||
[[self notificationLabel] setAttributedText:attributedString];
|
||||
}
|
||||
|
||||
- (void)displayNotificationWithView:(UIView *)view completion:(void (^)(void))completion
|
||||
{
|
||||
if (!self.notificationIsShowing) {
|
||||
self.isCustomView = YES;
|
||||
self.notificationIsShowing = YES;
|
||||
|
||||
// create UIWindow
|
||||
// create window
|
||||
[self createNotificationWindow];
|
||||
|
||||
// setup view
|
||||
@@ -523,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];
|
||||
@@ -531,9 +560,13 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dismissNotification
|
||||
- (void)displayNotificationWithView:(UIView *)view forDuration:(NSTimeInterval)duration
|
||||
{
|
||||
[self dismissNotificationWithCompletion:nil];
|
||||
[self displayNotificationWithView:view completion:^{
|
||||
self.dismissHandle = perform_block_after_delay(duration, ^{
|
||||
[self dismissNotification];
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)dismissNotificationWithCompletion:(void (^)(void))completion
|
||||
@@ -542,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;
|
||||
@@ -566,22 +599,8 @@ static void cancel_delayed_block(CWDelayedBlockHandle delayedHandle)
|
||||
}
|
||||
}
|
||||
|
||||
- (void)displayNotificationWithMessage:(NSString *)message forDuration:(CGFloat)duration
|
||||
- (void)dismissNotification
|
||||
{
|
||||
[self displayNotificationWithMessage:message completion:^{
|
||||
self.dismissHandle = perform_block_after_delay(duration, ^{
|
||||
[self dismissNotification];
|
||||
});
|
||||
}];
|
||||
[self dismissNotificationWithCompletion:nil];
|
||||
}
|
||||
|
||||
- (void)displayNotificationWithView:(UIView *)view forDuration:(CGFloat)duration
|
||||
{
|
||||
[self displayNotificationWithView:view completion:^{
|
||||
self.dismissHandle = perform_block_after_delay(duration, ^{
|
||||
[self dismissNotification];
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -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.2.6'`
|
||||
`pod 'CWStatusBarNotification', '~> 2.3.3'`
|
||||
|
||||
### 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