diff --git a/Classes/AFDropdownNotification.h b/Classes/AFDropdownNotification.h index 0b3970c..ca9d0a4 100644 --- a/Classes/AFDropdownNotification.h +++ b/Classes/AFDropdownNotification.h @@ -20,10 +20,10 @@ @interface AFDropdownNotification : NSObject typedef NS_ENUM(NSInteger, AFDropdownNotificationEvent) { - AFDropdownNotificationEventTopButton, AFDropdownNotificationEventBottomButton, - AFDropdownNotificationEventTap + AFDropdownNotificationEventTap, + AFDropdownNotificationEventSwipe }; typedef void (^block)(AFDropdownNotificationEvent event); @@ -37,6 +37,20 @@ typedef void (^block)(AFDropdownNotificationEvent event); @property (nonatomic, strong) UIImage *image; @property (nonatomic, strong) NSString *topButtonText; @property (nonatomic, strong) NSString *bottomButtonText; +@property (nonatomic, strong) UIFont *titleLabelFont; +@property (nonatomic, strong) UIColor *titleLabelColor; +@property (nonatomic, strong) UIFont *subtitleLabelFont; +@property (nonatomic, strong) UIColor *subtitleLabelColor; +@property (nonatomic, strong) UIFont *buttonFont; +@property (nonatomic, strong) UIColor *topButtonTextColor; +@property (nonatomic, strong) UIColor *topButtonBackgroundColor; +@property (nonatomic, strong) UIColor *topButtonBorderColor; +@property (nonatomic, strong) UIColor *bottomButtonTextColor; +@property (nonatomic, strong) UIColor *bottomButtonBackgroundColor; +@property (nonatomic, strong) UIColor *bottomButtonBorderColor; +@property (nonatomic) CGFloat buttonCornerRadius; +@property (nonatomic) CGFloat buttonBorderWidth; +@property (nonatomic, assign) UIBlurEffectStyle blurEffectStyle; @property (nonatomic) BOOL isBeingShown; @property (nonatomic) BOOL isImageRounded; @@ -47,5 +61,6 @@ typedef void (^block)(AFDropdownNotificationEvent event); -(void)dismissWithGravityAnimation:(BOOL)animation; @property (nonatomic) BOOL dismissOnTap; +@property (nonatomic) BOOL dismissOnSwipeUp; @end diff --git a/Classes/AFDropdownNotification.m b/Classes/AFDropdownNotification.m index 0ee90e5..5d4f42c 100644 --- a/Classes/AFDropdownNotification.m +++ b/Classes/AFDropdownNotification.m @@ -34,248 +34,287 @@ @interface AFDropdownNotification () @implementation AFDropdownNotification -(id)init { - + self = [super init]; - + if (self) { - + _notificationView = [UIView new]; _notificationView.backgroundColor = [UIColor whiteColor]; - + _titleLabel = [UILabel new]; - _titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:15]; - _titleLabel.textColor = [UIColor blackColor]; - + _subtitleLabel = [UILabel new]; - _subtitleLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:13]; _subtitleLabel.numberOfLines = 0; - _subtitleLabel.textColor = [UIColor blackColor]; - + _imageView = [UIImageView new]; _imageView.image = nil; - + _topButton = [UIButton buttonWithType:UIButtonTypeCustom]; - _topButton.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:13]; - [_topButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; _topButton.adjustsImageWhenHighlighted = YES; - _topButton.backgroundColor = [UIColor clearColor]; - - [_topButton.layer setCornerRadius:10]; - [_topButton.layer setBorderWidth:1]; - [_topButton.layer setBorderColor:[[UIColor grayColor] CGColor]]; - [_topButton.layer setMasksToBounds:YES]; - + _bottomButton = [UIButton buttonWithType:UIButtonTypeCustom]; - _bottomButton.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:13]; - [_bottomButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; - [_bottomButton.layer setCornerRadius:10]; - [_bottomButton.layer setBorderWidth:1]; - [_bottomButton.layer setBorderColor:[[UIColor grayColor] CGColor]]; - [_bottomButton.layer setMasksToBounds:YES]; - + _screenSize = [[UIScreen mainScreen] bounds].size; - + _dismissOnTap = NO; + _dismissOnSwipeUp = YES; } - + return self; } -(void)presentInView:(UIView *)view withGravityAnimation:(BOOL)animation { - + if (!_isBeingShown) { - + _imageView.image = _image; _titleLabel.text = _titleText; _subtitleLabel.text = _subtitleText; [_topButton setTitle:_topButtonText forState:UIControlStateNormal]; [_bottomButton setTitle:_bottomButtonText forState:UIControlStateNormal]; + _titleLabel.font = _titleLabelFont ? : [UIFont systemFontOfSize:15]; + _titleLabel.textColor = _titleLabelColor ? : [UIColor blackColor]; + + _subtitleLabel.font = _subtitleLabelFont ? : [UIFont systemFontOfSize:13]; + _subtitleLabel.textColor = _subtitleLabelColor ? : [UIColor blackColor]; + + _topButtonBackgroundColor = _topButtonBackgroundColor ? : [UIColor clearColor]; + _topButtonBorderColor = _topButtonBorderColor ? : [UIColor grayColor]; + + _buttonBorderWidth = _buttonBorderWidth ? : 1; + _buttonCornerRadius = _buttonCornerRadius ? : 10; + + _topButton.backgroundColor = _topButtonBackgroundColor; + _topButton.titleLabel.font = _buttonFont; + [_topButton setTitleColor:_topButtonTextColor forState:UIControlStateNormal]; + [_topButton.layer setCornerRadius:_buttonCornerRadius]; + [_topButton.layer setBorderWidth:_buttonBorderWidth]; + [_topButton.layer setBorderColor:_topButtonBorderColor.CGColor]; + [_topButton.layer setMasksToBounds:YES]; + + _bottomButtonBackgroundColor = _bottomButtonBackgroundColor ? : [UIColor clearColor]; + _bottomButtonBorderColor = _bottomButtonBorderColor ? : [UIColor grayColor]; + + _bottomButton.titleLabel.font = _buttonFont; + [_bottomButton setTitleColor:_bottomButtonTextColor forState:UIControlStateNormal]; + [_bottomButton.layer setCornerRadius:_buttonCornerRadius]; + [_bottomButton.layer setBorderWidth:_buttonBorderWidth]; + [_bottomButton.layer setBorderColor:_bottomButtonBorderColor.CGColor]; + [_bottomButton.layer setMasksToBounds:YES]; + NSInteger textWidth = ([[UIScreen mainScreen] bounds].size.width - kDropdownPadding - kDropdownImageSize - kDropdownPadding - kDropdownPadding - kDropdownButtonWidth - kDropdownPadding); NSInteger titleHeight = [_titleLabel.text boundingRectWithSize:CGSizeMake(textWidth, 999) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Medium" size:kDropdownTitleFontSize]} context:nil].size.height; NSInteger subtitleHeight = [_subtitleLabel.text boundingRectWithSize:CGSizeMake(textWidth, 999) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:kDropdownSubtitleFontSize]} context:nil].size.height; NSInteger notificationHeight = (20 + kDropdownPadding + titleHeight + (kDropdownPadding / 2) + subtitleHeight + kDropdownPadding); - + if (notificationHeight < 100) { - + notificationHeight = 100; } - + _notificationView.frame = CGRectMake(0, -notificationHeight, [[UIScreen mainScreen] bounds].size.width, notificationHeight); _notificationView.backgroundColor = [UIColor clearColor]; - + [[[UIApplication sharedApplication] keyWindow] addSubview:_notificationView]; [[[UIApplication sharedApplication] keyWindow] bringSubviewToFront:_notificationView]; - + if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) { - UIVisualEffect *visualEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; + _blurEffectStyle = _blurEffectStyle ? : UIBlurEffectStyleLight; + UIVisualEffect *visualEffect = [UIBlurEffect effectWithStyle:_blurEffectStyle]; UIVisualEffectView *blurView = [[UIVisualEffectView alloc] initWithEffect:visualEffect]; blurView.frame = _notificationView.bounds; [_notificationView addSubview:blurView]; } else { _notificationView.backgroundColor = [UIColor whiteColor]; } - + _imageView.frame = CGRectMake(kDropdownPadding, (notificationHeight / 2) - (kDropdownImageSize / 2) + (20 / 2), kDropdownImageSize, kDropdownImageSize); - + if (_image) { [_notificationView addSubview:_imageView]; - + if (self.isImageRounded) { self.imageView.clipsToBounds = YES; self.imageView.layer.cornerRadius = kDropdownImageSize/2; self.imageView.image = _image; } } - + _titleLabel.frame = CGRectMake(kDropdownPadding + kDropdownImageSize + kDropdownPadding, 20 + kDropdownPadding, textWidth, titleHeight); - + if (_titleText) { [_notificationView addSubview:_titleLabel]; } - + _subtitleLabel.frame = CGRectMake(kDropdownPadding + kDropdownImageSize + kDropdownPadding, _titleLabel.frame.origin.y + _titleLabel.frame.size.height + 3, textWidth, subtitleHeight); - + if (_subtitleText) { [_notificationView addSubview:_subtitleLabel]; } - + _topButton.frame = CGRectMake(_titleLabel.frame.origin.x + _titleLabel.frame.size.width + kDropdownPadding, 20 + (kDropdownPadding / 2), kDropdownButtonWidth, kDropdownButtonHeight); [_topButton addTarget:self action:@selector(topButtonTapped) forControlEvents:UIControlEventTouchUpInside]; - + if (_topButtonText) { [_notificationView addSubview:_topButton]; } - + _bottomButton.frame = CGRectMake(_titleLabel.frame.origin.x + _titleLabel.frame.size.width + kDropdownPadding, _topButton.frame.origin.y + _topButton.frame.size.height + 6, kDropdownButtonWidth, kDropdownButtonHeight); [_bottomButton addTarget:self action:@selector(bottomButtonTapped) forControlEvents:UIControlEventTouchUpInside]; - + if (_bottomButtonText) { [_notificationView addSubview:_bottomButton]; } - + if (_dismissOnTap) { - + UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss:)]; tap.numberOfTapsRequired = 1; [_notificationView addGestureRecognizer:tap]; } - if (animation) { + if (_dismissOnSwipeUp) { - _animator = [[UIDynamicAnimator alloc] initWithReferenceView:[[UIApplication sharedApplication] keyWindow]]; + UIPanGestureRecognizer *swipeUp = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]; + [_notificationView addGestureRecognizer:swipeUp]; + } + + if (animation) { + + _animator = [[UIDynamicAnimator alloc] initWithReferenceView:[[UIApplication sharedApplication] keyWindow]]; + UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:@[_notificationView]]; [_animator addBehavior:gravity]; - + UICollisionBehavior *collision = [[UICollisionBehavior alloc] initWithItems:@[_notificationView]]; collision.translatesReferenceBoundsIntoBoundary = NO; [collision addBoundaryWithIdentifier:@"notificationEnd" fromPoint:CGPointMake(0, notificationHeight) toPoint:CGPointMake([[UIScreen mainScreen] bounds].size.width, notificationHeight)]; [_animator addBehavior:collision]; - + UIDynamicItemBehavior *elasticityBehavior = [[UIDynamicItemBehavior alloc] initWithItems:@[_notificationView]]; elasticityBehavior.elasticity = 0.3f; [_animator addBehavior:elasticityBehavior]; } else { - + [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ - + _notificationView.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, notificationHeight); } completion:nil]; } - + _isBeingShown = YES; _gravityAnimation = animation; } - + _internalBlock = ^(AFDropdownNotificationEvent event) { - + }; } -(void)topButtonTapped { - + [self.notificationDelegate dropdownNotificationTopButtonTapped]; - + if (_internalBlock) { - + _internalBlock(AFDropdownNotificationEventTopButton); } } -(void)bottomButtonTapped { - + [self.notificationDelegate dropdownNotificationBottomButtonTapped]; - + // if (_internalBlock) { - + _internalBlock(AFDropdownNotificationEventBottomButton); // } } -(void)dismiss:(id)sender { - + [self dismissWithGravityAnimation:_gravityAnimation]; - + if ([sender isKindOfClass:[UITapGestureRecognizer class]]) { + + if (_internalBlock) { + + _internalBlock(AFDropdownNotificationEventTap); + } + } else if ([sender isKindOfClass:[UIPanGestureRecognizer class]]) { if (_internalBlock) { - _internalBlock(AFDropdownNotificationEventTap); + _internalBlock(AFDropdownNotificationEventSwipe); } } } -(void)dismissWithGravityAnimation:(BOOL)animation { - + if (animation) { - + UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:@[_notificationView]]; gravity.gravityDirection = CGVectorMake(0, -1.5); [_animator addBehavior:gravity]; - + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ - + [_animator removeAllBehaviors]; [self removeSubviews]; [_notificationView removeFromSuperview]; - + _isBeingShown = NO; }); } else { - + [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ - + [_animator removeAllBehaviors]; - + _notificationView.frame = CGRectMake(0, -_notificationView.frame.size.height, [[UIScreen mainScreen] bounds].size.width, _notificationView.frame.size.height); } completion:^(BOOL finished) { - + [self removeSubviews]; [_notificationView removeFromSuperview]; - + _isBeingShown = NO; }]; } } -(void)removeSubviews { - + for (UIView *subiew in _notificationView.subviews) { - + [subiew removeFromSuperview]; } } -(void)listenEventsWithBlock:(block)block { - + _internalBlock = ^(AFDropdownNotificationEvent event) { - + if (block) { - + block(event); } }; } +-(void)handlePan:(UIPanGestureRecognizer *)recognizer { + if (recognizer.state == UIGestureRecognizerStateChanged || recognizer.state == UIGestureRecognizerStateEnded) { + CGPoint velocity = [recognizer velocityInView:_notificationView]; + if (velocity.y < 0) { + if (recognizer.state == UIGestureRecognizerStateEnded) { + NSLog(@"Swipe up"); + [self dismiss:recognizer]; + } + } + } +} + @end diff --git a/Demo/AFDropdownNotification-Demo/AFDropdownNotification/AFDropdownNotification.h b/Demo/AFDropdownNotification-Demo/AFDropdownNotification/AFDropdownNotification.h index bc73bb5..ca9d0a4 100644 --- a/Demo/AFDropdownNotification-Demo/AFDropdownNotification/AFDropdownNotification.h +++ b/Demo/AFDropdownNotification-Demo/AFDropdownNotification/AFDropdownNotification.h @@ -20,10 +20,10 @@ @interface AFDropdownNotification : NSObject typedef NS_ENUM(NSInteger, AFDropdownNotificationEvent) { - AFDropdownNotificationEventTopButton, AFDropdownNotificationEventBottomButton, - AFDropdownNotificationEventTap + AFDropdownNotificationEventTap, + AFDropdownNotificationEventSwipe }; typedef void (^block)(AFDropdownNotificationEvent event); @@ -37,8 +37,23 @@ typedef void (^block)(AFDropdownNotificationEvent event); @property (nonatomic, strong) UIImage *image; @property (nonatomic, strong) NSString *topButtonText; @property (nonatomic, strong) NSString *bottomButtonText; +@property (nonatomic, strong) UIFont *titleLabelFont; +@property (nonatomic, strong) UIColor *titleLabelColor; +@property (nonatomic, strong) UIFont *subtitleLabelFont; +@property (nonatomic, strong) UIColor *subtitleLabelColor; +@property (nonatomic, strong) UIFont *buttonFont; +@property (nonatomic, strong) UIColor *topButtonTextColor; +@property (nonatomic, strong) UIColor *topButtonBackgroundColor; +@property (nonatomic, strong) UIColor *topButtonBorderColor; +@property (nonatomic, strong) UIColor *bottomButtonTextColor; +@property (nonatomic, strong) UIColor *bottomButtonBackgroundColor; +@property (nonatomic, strong) UIColor *bottomButtonBorderColor; +@property (nonatomic) CGFloat buttonCornerRadius; +@property (nonatomic) CGFloat buttonBorderWidth; +@property (nonatomic, assign) UIBlurEffectStyle blurEffectStyle; @property (nonatomic) BOOL isBeingShown; +@property (nonatomic) BOOL isImageRounded; -(void)listenEventsWithBlock:(block)block; @@ -46,5 +61,6 @@ typedef void (^block)(AFDropdownNotificationEvent event); -(void)dismissWithGravityAnimation:(BOOL)animation; @property (nonatomic) BOOL dismissOnTap; +@property (nonatomic) BOOL dismissOnSwipeUp; @end diff --git a/Demo/AFDropdownNotification-Demo/AFDropdownNotification/AFDropdownNotification.m b/Demo/AFDropdownNotification-Demo/AFDropdownNotification/AFDropdownNotification.m index df9f40a..681a2f0 100644 --- a/Demo/AFDropdownNotification-Demo/AFDropdownNotification/AFDropdownNotification.m +++ b/Demo/AFDropdownNotification-Demo/AFDropdownNotification/AFDropdownNotification.m @@ -43,39 +43,22 @@ -(id)init { _notificationView.backgroundColor = [UIColor whiteColor]; _titleLabel = [UILabel new]; - _titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:15]; - _titleLabel.textColor = [UIColor blackColor]; _subtitleLabel = [UILabel new]; - _subtitleLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:13]; _subtitleLabel.numberOfLines = 0; - _subtitleLabel.textColor = [UIColor blackColor]; _imageView = [UIImageView new]; _imageView.image = nil; _topButton = [UIButton buttonWithType:UIButtonTypeCustom]; - _topButton.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:13]; - [_topButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; _topButton.adjustsImageWhenHighlighted = YES; - _topButton.backgroundColor = [UIColor clearColor]; - - [_topButton.layer setCornerRadius:10]; - [_topButton.layer setBorderWidth:1]; - [_topButton.layer setBorderColor:[[UIColor grayColor] CGColor]]; - [_topButton.layer setMasksToBounds:YES]; _bottomButton = [UIButton buttonWithType:UIButtonTypeCustom]; - _bottomButton.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:13]; - [_bottomButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; - [_bottomButton.layer setCornerRadius:10]; - [_bottomButton.layer setBorderWidth:1]; - [_bottomButton.layer setBorderColor:[[UIColor grayColor] CGColor]]; - [_bottomButton.layer setMasksToBounds:YES]; _screenSize = [[UIScreen mainScreen] bounds].size; _dismissOnTap = NO; + _dismissOnSwipeUp = NO; } return self; @@ -91,6 +74,36 @@ -(void)presentInView:(UIView *)view withGravityAnimation:(BOOL)animation { [_topButton setTitle:_topButtonText forState:UIControlStateNormal]; [_bottomButton setTitle:_bottomButtonText forState:UIControlStateNormal]; + _titleLabel.font = _titleLabelFont ? : [UIFont systemFontOfSize:15]; + _titleLabel.textColor = _titleLabelColor ? : [UIColor blackColor]; + + _subtitleLabel.font = _subtitleLabelFont ? : [UIFont systemFontOfSize:13]; + _subtitleLabel.textColor = _subtitleLabelColor ? : [UIColor blackColor]; + + _topButtonBackgroundColor = _topButtonBackgroundColor ? : [UIColor clearColor]; + _topButtonBorderColor = _topButtonBorderColor ? : [UIColor grayColor]; + + _buttonBorderWidth = _buttonBorderWidth ? : 1; + _buttonCornerRadius = _buttonCornerRadius ? : 10; + + _topButton.backgroundColor = _topButtonBackgroundColor; + _topButton.titleLabel.font = _buttonFont; + [_topButton setTitleColor:_topButtonTextColor forState:UIControlStateNormal]; + [_topButton.layer setCornerRadius:_buttonCornerRadius]; + [_topButton.layer setBorderWidth:_buttonBorderWidth]; + [_topButton.layer setBorderColor:_topButtonBorderColor.CGColor]; + [_topButton.layer setMasksToBounds:YES]; + + _bottomButtonBackgroundColor = _bottomButtonBackgroundColor ? : [UIColor clearColor]; + _bottomButtonBorderColor = _bottomButtonBorderColor ? : [UIColor grayColor]; + + _bottomButton.titleLabel.font = _buttonFont; + [_bottomButton setTitleColor:_bottomButtonTextColor forState:UIControlStateNormal]; + [_bottomButton.layer setCornerRadius:_buttonCornerRadius]; + [_bottomButton.layer setBorderWidth:_buttonBorderWidth]; + [_bottomButton.layer setBorderColor:_bottomButtonBorderColor.CGColor]; + [_bottomButton.layer setMasksToBounds:YES]; + NSInteger textWidth = ([[UIScreen mainScreen] bounds].size.width - kDropdownPadding - kDropdownImageSize - kDropdownPadding - kDropdownPadding - kDropdownButtonWidth - kDropdownPadding); NSInteger titleHeight = [_titleLabel.text boundingRectWithSize:CGSizeMake(textWidth, 999) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Medium" size:kDropdownTitleFontSize]} context:nil].size.height; NSInteger subtitleHeight = [_subtitleLabel.text boundingRectWithSize:CGSizeMake(textWidth, 999) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:kDropdownSubtitleFontSize]} context:nil].size.height; @@ -108,7 +121,8 @@ -(void)presentInView:(UIView *)view withGravityAnimation:(BOOL)animation { [[[UIApplication sharedApplication] keyWindow] bringSubviewToFront:_notificationView]; if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) { - UIVisualEffect *visualEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; + _blurEffectStyle = _blurEffectStyle ? : UIBlurEffectStyleLight; + UIVisualEffect *visualEffect = [UIBlurEffect effectWithStyle:_blurEffectStyle]; UIVisualEffectView *blurView = [[UIVisualEffectView alloc] initWithEffect:visualEffect]; blurView.frame = _notificationView.bounds; [_notificationView addSubview:blurView]; @@ -120,6 +134,12 @@ -(void)presentInView:(UIView *)view withGravityAnimation:(BOOL)animation { if (_image) { [_notificationView addSubview:_imageView]; + + if (self.isImageRounded) { + self.imageView.clipsToBounds = YES; + self.imageView.layer.cornerRadius = kDropdownImageSize/2; + self.imageView.image = _image; + } } _titleLabel.frame = CGRectMake(kDropdownPadding + kDropdownImageSize + kDropdownPadding, 20 + kDropdownPadding, textWidth, titleHeight); @@ -153,6 +173,14 @@ -(void)presentInView:(UIView *)view withGravityAnimation:(BOOL)animation { UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss:)]; tap.numberOfTapsRequired = 1; [_notificationView addGestureRecognizer:tap]; + + } + + if (_dismissOnSwipeUp) { + + UIPanGestureRecognizer *swipeUp = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]; + [_notificationView addGestureRecognizer:swipeUp]; + } if (animation) { @@ -201,10 +229,10 @@ -(void)bottomButtonTapped { [self.notificationDelegate dropdownNotificationBottomButtonTapped]; -// if (_internalBlock) { + // if (_internalBlock) { - _internalBlock(AFDropdownNotificationEventBottomButton); -// } + _internalBlock(AFDropdownNotificationEventBottomButton); + // } } -(void)dismiss:(id)sender { @@ -217,6 +245,12 @@ -(void)dismiss:(id)sender { _internalBlock(AFDropdownNotificationEventTap); } + } else if ([sender isKindOfClass:[UIPanGestureRecognizer class]]) { + + if (_internalBlock) { + + _internalBlock(AFDropdownNotificationEventSwipe); + } } } @@ -239,7 +273,9 @@ -(void)dismissWithGravityAnimation:(BOOL)animation { } else { [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ - + + [_animator removeAllBehaviors]; + _notificationView.frame = CGRectMake(0, -_notificationView.frame.size.height, [[UIScreen mainScreen] bounds].size.width, _notificationView.frame.size.height); } completion:^(BOOL finished) { @@ -270,4 +306,16 @@ -(void)listenEventsWithBlock:(block)block { }; } +-(void)handlePan:(UIPanGestureRecognizer *)recognizer { + if (recognizer.state == UIGestureRecognizerStateChanged || recognizer.state == UIGestureRecognizerStateEnded) { + CGPoint velocity = [recognizer velocityInView:_notificationView]; + if (velocity.y < 0) { + if (recognizer.state == UIGestureRecognizerStateEnded) { + NSLog(@"Swipe up"); + [self dismiss:recognizer]; + } + } + } +} + @end diff --git a/Demo/AFDropdownNotification-Demo/ViewController.m b/Demo/AFDropdownNotification-Demo/ViewController.m index 93678db..0b40e55 100644 --- a/Demo/AFDropdownNotification-Demo/ViewController.m +++ b/Demo/AFDropdownNotification-Demo/ViewController.m @@ -32,6 +32,7 @@ -(IBAction)showNotification:(id)sender { _notification.topButtonText = @"Accept"; _notification.bottomButtonText = @"Cancel"; _notification.dismissOnTap = YES; + _notification.dismissOnSwipeUp = YES; [_notification presentInView:self.view withGravityAnimation:YES]; [_notification listenEventsWithBlock:^(AFDropdownNotificationEvent event) {