Compare commits

..

10 Commits

Author SHA1 Message Date
Cezary Wojcik 9704c4a593 2.1.1 2014-03-15 15:09:34 -07:00
Cezary Wojcik 2504969cdf fixed from bottom animation 2014-03-15 12:39:30 -07:00
Cezary Wojcik 34574e0309 Merge pull request #11 from mstrchrstphr/master
Update README.md
2014-02-17 17:50:04 -08:00
Christopher Constable 3a0e5081b4 Update README.md 2014-02-17 19:49:00 -05:00
Cezary Wojcik d68d5acaa0 Merge pull request #8 from dannybabiy/master
Allow for longer text, and appearance options for when you don't have a visible status bar.
2013-12-26 22:31:18 -08:00
Danny Babiy 04c750b19f allow for multiline 2013-12-26 21:57:19 -05:00
Danny Babiy 7169617a68 allow to set a custom label height 2013-12-26 14:22:05 -05:00
Danny Babiy e6cee95c7d allow for overlay type of animation 2013-12-26 14:19:53 -05:00
Danny Babiy 2431285d57 scroll long text 2013-12-26 12:40:30 -05:00
Cezary Wojcik d64336e03e cocoapod 2013-11-17 10:27:20 -08:00
5 changed files with 98 additions and 22 deletions
+1 -5
View File
@@ -202,7 +202,7 @@
5E2FFB4B18367C01003333F8 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0500;
LastUpgradeCheck = 0510;
ORGANIZATIONNAME = "Cezary Wojcik";
TargetAttributes = {
5E2FFB5218367C01003333F8 = {
@@ -296,7 +296,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
@@ -336,7 +335,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
@@ -401,7 +399,6 @@
5E2FFB8318367C01003333F8 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/CWNotificationDemo.app/CWNotificationDemo";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
@@ -424,7 +421,6 @@
5E2FFB8418367C01003333F8 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/CWNotificationDemo.app/CWNotificationDemo";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
+1 -1
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "CWStatusBarNotification"
s.version = "2.1.0"
s.version = "2.1.1"
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 = "http://github.com/cezarywojcik/CWStatusBarNotification"
@@ -8,29 +8,41 @@
#import <Foundation/Foundation.h>
@interface ScrollLabel : UILabel
- (CGFloat)scrollTime;
@end
@interface CWStatusBarNotification : NSObject
enum {
typedef NS_ENUM(NSInteger, CWNotificationStyle) {
CWNotificationStyleStatusBarNotification,
CWNotificationStyleNavigationBarNotification
};
enum {
typedef NS_ENUM(NSInteger, CWNotificationAnimationStyle) {
CWNotificationAnimationStyleTop,
CWNotificationAnimationStyleBottom,
CWNotificationAnimationStyleLeft,
CWNotificationAnimationStyleRight
};
@property (strong, nonatomic) UILabel *notificationLabel;
typedef NS_ENUM(NSInteger, CWNotificationAnimationType) {
CWNotificationAnimationTypeReplace,
CWNotificationAnimationTypeOverlay
};
@property (strong, nonatomic) ScrollLabel *notificationLabel;
@property (strong, nonatomic) UIColor *notificationLabelBackgroundColor;
@property (strong, nonatomic) UIColor *notificationLabelTextColor;
@property (assign, nonatomic) CGFloat notificationLabelHeight;
@property (assign, nonatomic) BOOL multiline;
@property (strong, nonatomic) UIView *statusBarView;
@property (nonatomic) NSInteger notificationStyle;
@property (nonatomic) NSInteger notificationAnimationInStyle;
@property (nonatomic) NSInteger notificationAnimationOutStyle;
@property (nonatomic) CWNotificationAnimationStyle notificationStyle;
@property (nonatomic) CWNotificationAnimationStyle notificationAnimationInStyle;
@property (nonatomic) CWNotificationAnimationStyle notificationAnimationOutStyle;
@property (nonatomic) CWNotificationAnimationType notificationAnimationType;
@property (nonatomic) BOOL notificationIsShowing;
@property (strong, nonatomic) UIWindow *notificationWindow;
@@ -12,6 +12,64 @@
#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 - CWStatusBarNotification
@implementation CWStatusBarNotification
@@ -30,6 +88,7 @@
self.notificationStyle = CWNotificationStyleStatusBarNotification;
self.notificationAnimationInStyle = CWNotificationAnimationStyleBottom;
self.notificationAnimationOutStyle = CWNotificationAnimationStyleBottom;
self.notificationAnimationType = CWNotificationAnimationTypeReplace;
}
return self;
}
@@ -37,11 +96,14 @@
# pragma mark - dimensions
- (CGFloat)getStatusBarHeight {
if (self.notificationLabelHeight > 0) {
return self.notificationLabelHeight;
}
CGFloat statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
if (UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.width;
}
return statusBarHeight;
return statusBarHeight > 0 ? statusBarHeight : 20;
}
- (CGFloat)getStatusBarWidth {
@@ -101,13 +163,15 @@
- (void)createNotificationLabelWithMessage:(NSString *)message
{
self.notificationLabel = [UILabel new];
self.notificationLabel = [ScrollLabel new];
self.notificationLabel.numberOfLines = self.multiline ? 0 : 1;
self.notificationLabel.text = message;
self.notificationLabel.textAlignment = NSTextAlignmentCenter;
self.notificationLabel.adjustsFontSizeToFitWidth = YES;
self.notificationLabel.adjustsFontSizeToFitWidth = NO;
self.notificationLabel.font = [UIFont systemFontOfSize:FONT_SIZE];
self.notificationLabel.backgroundColor = self.notificationLabelBackgroundColor;
self.notificationLabel.textColor = self.notificationLabelTextColor;
self.notificationLabel.clipsToBounds = YES;
switch (self.notificationAnimationInStyle) {
case CWNotificationAnimationStyleTop:
self.notificationLabel.frame = [self getNotificationLabelTopFrame];
@@ -140,8 +204,10 @@
{
self.statusBarView = [[UIView alloc] initWithFrame:[self getNotificationLabelFrame]];
self.statusBarView.clipsToBounds = YES;
UIView *statusBarImageView = [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:YES];
[self.statusBarView addSubview:statusBarImageView];
if (self.notificationAnimationType == CWNotificationAnimationTypeReplace) {
UIView *statusBarImageView = [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:YES];
[self.statusBarView addSubview:statusBarImageView];
}
[self.notificationWindow.rootViewController.view addSubview:self.statusBarView];
[self.notificationWindow.rootViewController.view sendSubviewToBack:self.statusBarView];
}
@@ -234,7 +300,11 @@
[UIView animateWithDuration:STATUS_BAR_ANIMATION_LENGTH animations:^{
[self firstFrameChange];
} completion:^(BOOL finished) {
[completion invoke];
double delayInSeconds = [self.notificationLabel scrollTime];
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[completion invoke];
});
}];
}
+2 -4
View File
@@ -14,7 +14,7 @@ Works for iPhone and iPad.
### CocoaPods
`pod 'CWStatusBarNotification', '~> 2.0.0'`
`pod 'CWStatusBarNotification', '~> 2.1.1'`
### Manual
@@ -47,7 +47,7 @@ If you prefer to manually choose when to display and dismiss the notification, y
```
[self.notification displayNotificationWithMessage:@"Hello" completion:nil];
// wait until you need to dismiss
[self.notofication dismissNotification];
[self.notification dismissNotification];
```
## Customizing Appearance
@@ -115,5 +115,3 @@ The notifications will work in both screen orientations, however, screen rotatio
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.