diff --git a/RNBlurModalView.h b/RNBlurModalView.h index c339e23..6ee0dc2 100644 --- a/RNBlurModalView.h +++ b/RNBlurModalView.h @@ -29,7 +29,7 @@ extern NSString * const kRNBlurDidShowNotification; extern NSString * const kRNBlurDidHidewNotification; -@interface RNBlurModalView : UIView +@interface RNBlurModalView : UIView @property (assign, readonly) BOOL isVisible; @@ -52,7 +52,7 @@ extern NSString * const kRNBlurDidHidewNotification; - (void)hide; - (void)hideWithDuration:(CGFloat)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options completion:(void (^)(void))completion; --(void)hideCloseButton:(BOOL)hide; +- (void)hideCloseButton:(BOOL)hide; +- (void)tapAnywhereToClose:(BOOL)tap; - -@end \ No newline at end of file +@end diff --git a/RNBlurModalView.m b/RNBlurModalView.m index e753f46..a9e7e86 100644 --- a/RNBlurModalView.m +++ b/RNBlurModalView.m @@ -91,6 +91,7 @@ @implementation RNBlurModalView { RNCloseButton *_dismissButton; RNBlurView *_blurView; RNBlurCompletion _completion; + UITapGestureRecognizer *_tapGesture; } + (UIView*)generateModalViewWithTitle:(NSString*)title message:(NSString*)message { @@ -158,6 +159,9 @@ - (id)initWithFrame:(CGRect)frame { UIViewAutoresizingFlexibleTopMargin); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChangeNotification:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; + + _tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)]; + } return self; } @@ -189,7 +193,7 @@ - (id)initWithViewController:(UIViewController*)viewController title:(NSString*) return self; } -- (id)initWithParentView:(UIView*)parentView view:(UIView*)view { +- (id)initWithParentView:(UIView*)parentView view:(UIView*)view { if (self = [self initWithFrame:CGRectMake(0, 0, parentView.width, parentView.height)]) { [self addSubview:view]; _contentView = view; @@ -199,6 +203,7 @@ - (id)initWithParentView:(UIView*)parentView view:(UIView*)view { _contentView.clipsToBounds = YES; _contentView.layer.masksToBounds = YES; + _dismissButton.center = CGPointMake(view.left, view.top); [self addSubview:_dismissButton]; } @@ -379,10 +384,18 @@ - (void)hideWithDuration:(CGFloat)duration delay:(NSTimeInterval)delay options:( } } --(void)hideCloseButton:(BOOL)hide { +- (void)hideCloseButton:(BOOL)hide { [_dismissButton setHidden:hide]; } +- (void)tapAnywhereToClose:(BOOL)tap { + if (tap) { + [_contentView.superview addGestureRecognizer:_tapGesture]; + } else { + [_contentView.superview removeGestureRecognizer:_tapGesture]; + } +} + @end #pragma mark - RNBlurView