From 74b348408d1cb5705f5f455d4d93867dc46e7e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=80=B2=E6=92=83=E3=81=AE=E6=8A=80=E8=A1=93=E8=80=85?= Date: Mon, 24 Nov 2014 15:50:51 +0800 Subject: [PATCH] IOS6 compatibility IOS6 compatibility --- .../LNNotificationBannerView.m | 3 + .../LNNotificationBannerWindow.m | 184 +++++++++++++----- 2 files changed, 133 insertions(+), 54 deletions(-) mode change 100644 => 100755 LNNotificationsUI/LNNotificationsUI/LNNotificationBannerView.m mode change 100644 => 100755 LNNotificationsUI/LNNotificationsUI/LNNotificationBannerWindow.m diff --git a/LNNotificationsUI/LNNotificationsUI/LNNotificationBannerView.m b/LNNotificationsUI/LNNotificationsUI/LNNotificationBannerView.m old mode 100644 new mode 100755 index ffb4c86..07c3cb6 --- a/LNNotificationsUI/LNNotificationsUI/LNNotificationBannerView.m +++ b/LNNotificationsUI/LNNotificationsUI/LNNotificationBannerView.m @@ -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]; @@ -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]; @@ -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]) diff --git a/LNNotificationsUI/LNNotificationsUI/LNNotificationBannerWindow.m b/LNNotificationsUI/LNNotificationsUI/LNNotificationBannerWindow.m old mode 100644 new mode 100755 index 2bee8f8..e196424 --- a/LNNotificationsUI/LNNotificationsUI/LNNotificationBannerWindow.m +++ b/LNNotificationsUI/LNNotificationsUI/LNNotificationBannerWindow.m @@ -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; @@ -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 { @@ -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(); + } + }); + }]; + } } } @@ -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