From 30da830a7c8284478272506c98f5c55c37ec9610 Mon Sep 17 00:00:00 2001 From: Patrick Kladek Date: Sun, 17 Sep 2023 12:09:57 +0400 Subject: [PATCH] add gesture recognizer --- MBProgressHUD.h | 6 ++++++ MBProgressHUD.m | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/MBProgressHUD.h b/MBProgressHUD.h index bf7133fb2..2df2cfc6a 100644 --- a/MBProgressHUD.h +++ b/MBProgressHUD.h @@ -70,6 +70,7 @@ typedef NS_ENUM(NSInteger, MBProgressHUDBackgroundStyle) { }; typedef void (^MBProgressHUDCompletionBlock)(void); +typedef void (^MBProgressHUDTappedBlock)(void); NS_ASSUME_NONNULL_BEGIN @@ -183,6 +184,11 @@ NS_ASSUME_NONNULL_BEGIN */ @property (copy, nullable) MBProgressHUDCompletionBlock completionBlock; +/** + * Called after tapping the HUD or backgroundView + */ +@property (copy, nullable) MBProgressHUDTappedBlock tappedBlock; + /** * Grace period is the time (in seconds) that the invoked method may be run without * showing the HUD. If the task finishes before the grace time runs out, the HUD will diff --git a/MBProgressHUD.m b/MBProgressHUD.m index a2829a390..55963885d 100644 --- a/MBProgressHUD.m +++ b/MBProgressHUD.m @@ -100,6 +100,7 @@ - (void)commonInit { [self setupViews]; [self updateIndicators]; [self registerForNotifications]; + [self setupGestureRecognizer]; } - (instancetype)initWithFrame:(CGRect)frame { @@ -506,6 +507,12 @@ - (void)updateBezelMotionEffects { } } +- (void)setupGestureRecognizer { + UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_hudTapped:)]; + [self.backgroundView addGestureRecognizer:recognizer]; + [self addGestureRecognizer:recognizer]; +} + #pragma mark - Layout - (void)updateConstraints { @@ -805,6 +812,15 @@ - (void)updateForCurrentOrientationAnimated:(BOOL)animated { #endif } +#pragma mark - Private + +- (void)_hudTapped:(UIGestureRecognizer *)recognizer +{ + if (self.tappedBlock != nil) { + self.tappedBlock(); + } +} + @end