Skip to content
This repository has been archived by the owner on Nov 21, 2017. It is now read-only.

Commit

Permalink
IOS6 compatibility
Browse files Browse the repository at this point in the history
IOS6 compatibility
  • Loading branch information
refusebt committed Nov 24, 2014
1 parent 0447faf commit 74b3484
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 54 deletions.
3 changes: 3 additions & 0 deletions LNNotificationsUI/LNNotificationsUI/LNNotificationBannerView.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ - (instancetype)initWithFrame:(CGRect)frame style:(LNNotificationBannerStyle)sty
_titleLabel.font = [UIFont boldSystemFontOfSize:13];
_titleLabel.textColor = style == LNNotificationBannerStyleDark ? [UIColor whiteColor] : [UIColor blackColor];
_titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
_titleLabel.backgroundColor = [UIColor clearColor];

[_notificationContentView addSubview:_titleLabel];

Expand All @@ -152,6 +153,7 @@ - (instancetype)initWithFrame:(CGRect)frame style:(LNNotificationBannerStyle)sty
_messageLabel.textColor = style == LNNotificationBannerStyleDark ? [UIColor whiteColor] : [UIColor blackColor];
_messageLabel.translatesAutoresizingMaskIntoConstraints = NO;
_messageLabel.numberOfLines = 2;
_messageLabel.backgroundColor = [UIColor clearColor];

[_notificationContentView addSubview:_messageLabel];

Expand All @@ -166,6 +168,7 @@ - (instancetype)initWithFrame:(CGRect)frame style:(LNNotificationBannerStyle)sty
[_dateLabel setContentCompressionResistancePriority:1000 forAxis:UILayoutConstraintAxisVertical];
[_dateLabel setContentHuggingPriority:1000 forAxis:UILayoutConstraintAxisHorizontal];
[_dateLabel setContentHuggingPriority:1000 forAxis:UILayoutConstraintAxisVertical];
_dateLabel.backgroundColor = [UIColor clearColor];

UIView<_LNBackgroundViewCommon>* dateBG;
if([UIVisualEffectView class])
Expand Down
184 changes: 130 additions & 54 deletions LNNotificationsUI/LNNotificationsUI/LNNotificationBannerWindow.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#import "LNNotificationBannerView.h"
#import "LNNotificationCenter.h"

#define IS_IOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)

static const NSTimeInterval LNNotificationAnimationDuration = 0.5;
static const NSTimeInterval LNNotificationFullDuration = 5.0;
static const NSTimeInterval LNNotificationCutOffDuration = 2.5;
Expand Down Expand Up @@ -162,24 +164,50 @@ - (void)presentNotification:(LNNotification *)notification completionBlock:(void
_topConstraint.constant = -LNNotificationViewHeight;
[self layoutIfNeeded];

[UIView animateWithDuration:LNNotificationAnimationDuration delay:delay usingSpringWithDamping:500 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
_topConstraint.constant = 0;
[self layoutIfNeeded];
} completion:^(BOOL finished) {
_lastShowDate = [NSDate date];
_notificationViewShown = YES;

_pendingCompletionHandler = completionBlock;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(LNNotificationCutOffDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if(_pendingCompletionHandler)
{
void (^prevPendingCompletionHandler)() = _pendingCompletionHandler;
_pendingCompletionHandler = nil;
prevPendingCompletionHandler();
}
});
}];
if (IS_IOS7)
{
[UIView animateWithDuration:LNNotificationAnimationDuration delay:delay usingSpringWithDamping:500 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
_topConstraint.constant = 0;
[self layoutIfNeeded];
} completion:^(BOOL finished) {
_lastShowDate = [NSDate date];
_notificationViewShown = YES;

_pendingCompletionHandler = completionBlock;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(LNNotificationCutOffDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if(_pendingCompletionHandler)
{
void (^prevPendingCompletionHandler)() = _pendingCompletionHandler;
_pendingCompletionHandler = nil;
prevPendingCompletionHandler();
}
});
}];
}
else
{
[UIView animateWithDuration:LNNotificationAnimationDuration delay:delay options:UIViewAnimationOptionCurveEaseInOut
animations:^{
_topConstraint.constant = 0;
[self layoutIfNeeded];
}
completion:^(BOOL finished) {
_lastShowDate = [NSDate date];
_notificationViewShown = YES;

_pendingCompletionHandler = completionBlock;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(LNNotificationCutOffDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if(_pendingCompletionHandler)
{
void (^prevPendingCompletionHandler)() = _pendingCompletionHandler;
_pendingCompletionHandler = nil;
prevPendingCompletionHandler();
}
});
}];
}
}
else
{
Expand All @@ -192,27 +220,52 @@ - (void)presentNotification:(LNNotification *)notification completionBlock:(void

[_notificationView.notificationContentView.superview insertSubview:snapshot belowSubview:_notificationView.notificationContentView];



[UIView animateWithDuration:0.75 * LNNotificationAnimationDuration delay:delay usingSpringWithDamping:500 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
frame.origin.y = 0;
_notificationView.notificationContentView.frame = frame;
snapshot.alpha = 0;
} completion:^(BOOL finished) {
[snapshot removeFromSuperview];
_lastShowDate = [NSDate date];

_pendingCompletionHandler = completionBlock;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(LNNotificationCutOffDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if(_pendingCompletionHandler)
{
void (^prevPendingCompletionHandler)() = _pendingCompletionHandler;
_pendingCompletionHandler = nil;
prevPendingCompletionHandler();
}
});
}];
if (IS_IOS7)
{
[UIView animateWithDuration:0.75 * LNNotificationAnimationDuration delay:delay usingSpringWithDamping:500 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
frame.origin.y = 0;
_notificationView.notificationContentView.frame = frame;
snapshot.alpha = 0;
} completion:^(BOOL finished) {
[snapshot removeFromSuperview];
_lastShowDate = [NSDate date];

_pendingCompletionHandler = completionBlock;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(LNNotificationCutOffDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if(_pendingCompletionHandler)
{
void (^prevPendingCompletionHandler)() = _pendingCompletionHandler;
_pendingCompletionHandler = nil;
prevPendingCompletionHandler();
}
});
}];
}
else
{
[UIView animateWithDuration:0.75 * LNNotificationAnimationDuration delay:delay options:UIViewAnimationOptionCurveEaseInOut
animations:^{
frame.origin.y = 0;
_notificationView.notificationContentView.frame = frame;
snapshot.alpha = 0;
}
completion:^(BOOL finished) {
[snapshot removeFromSuperview];
_lastShowDate = [NSDate date];

_pendingCompletionHandler = completionBlock;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(LNNotificationCutOffDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if(_pendingCompletionHandler)
{
void (^prevPendingCompletionHandler)() = _pendingCompletionHandler;
_pendingCompletionHandler = nil;
prevPendingCompletionHandler();
}
});
}];
}
}
}

Expand Down Expand Up @@ -248,21 +301,44 @@ - (void)_dismissNotificationViewWithCompletionBlock:(void (^)())completionBlock
_notificationViewShown = NO;
});

[UIView animateWithDuration:LNNotificationAnimationDuration delay:delay usingSpringWithDamping:500 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState animations:^{
_topConstraint.constant = -LNNotificationViewHeight;
[self layoutIfNeeded];
} completion:^(BOOL finished) {
_lastShowDate = nil;
_notificationViewShown = NO;
[_notificationView configureForNotification:nil];

if(_pendingCompletionHandler)
{
void (^prevPendingCompletionHandler)() = _pendingCompletionHandler;
_pendingCompletionHandler = nil;
prevPendingCompletionHandler();
}
}];
if (IS_IOS7)
{
[UIView animateWithDuration:LNNotificationAnimationDuration delay:delay usingSpringWithDamping:500 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState animations:^{
_topConstraint.constant = -LNNotificationViewHeight;
[self layoutIfNeeded];
} completion:^(BOOL finished) {
_lastShowDate = nil;
_notificationViewShown = NO;
[_notificationView configureForNotification:nil];

if(_pendingCompletionHandler)
{
void (^prevPendingCompletionHandler)() = _pendingCompletionHandler;
_pendingCompletionHandler = nil;
prevPendingCompletionHandler();
}
}];
}
else
{
[UIView animateWithDuration:LNNotificationAnimationDuration delay:delay options:UIViewAnimationOptionCurveEaseInOut
animations:^{
_topConstraint.constant = -LNNotificationViewHeight;
[self layoutIfNeeded];
}
completion:^(BOOL finished) {
_lastShowDate = nil;
_notificationViewShown = NO;
[_notificationView configureForNotification:nil];

if(_pendingCompletionHandler)
{
void (^prevPendingCompletionHandler)() = _pendingCompletionHandler;
_pendingCompletionHandler = nil;
prevPendingCompletionHandler();
}
}];
}
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
Expand Down

0 comments on commit 74b3484

Please sign in to comment.