From a7ee33e9fddbcd7f0053e60c97e8552bd3cc20e2 Mon Sep 17 00:00:00 2001 From: Raul Uranga Date: Thu, 8 Aug 2013 18:31:37 -0500 Subject: [PATCH 1/4] make public default variables. the user can modify now these variables outside RNBlurModalView class. --- RNBlurModalView.h | 6 ++++++ RNBlurModalView.m | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/RNBlurModalView.h b/RNBlurModalView.h index c339e23..b5d39ef 100644 --- a/RNBlurModalView.h +++ b/RNBlurModalView.h @@ -26,6 +26,12 @@ #import #import +extern CGFloat kRNBlurDefaultDelay; +extern CGFloat kRNDefaultBlurScale; +extern CGFloat kRNBlurDefaultDuration; +extern CGFloat kRNBlurViewMaxAlpha; +extern CGFloat kRNBlurBounceOutDurationScale; + extern NSString * const kRNBlurDidShowNotification; extern NSString * const kRNBlurDidHidewNotification; diff --git a/RNBlurModalView.m b/RNBlurModalView.m index e753f46..db75f66 100644 --- a/RNBlurModalView.m +++ b/RNBlurModalView.m @@ -31,17 +31,17 @@ This bit is important! In order to prevent capturing selected states of UIResponders I've implemented a delay. Please feel free to set this delay to *whatever* you deem apprpriate. I've defaulted it to 0.125 seconds. You can do shorter/longer as you see fit. */ -CGFloat const kRNBlurDefaultDelay = 0.125f; +CGFloat kRNBlurDefaultDelay = 0.125f; /* You can also change this constant to make the blur more "blurry". I recommend the tasteful level of 0.2 and no higher. However, you are free to change this from 0.0 to 1.0. */ -CGFloat const kRNDefaultBlurScale = 0.2f; +CGFloat kRNDefaultBlurScale = 0.2f; -CGFloat const kRNBlurDefaultDuration = 0.2f; -CGFloat const kRNBlurViewMaxAlpha = 1.f; +CGFloat kRNBlurDefaultDuration = 0.2f; +CGFloat kRNBlurViewMaxAlpha = 1.f; -CGFloat const kRNBlurBounceOutDurationScale = 0.8f; +CGFloat kRNBlurBounceOutDurationScale = 0.8f; NSString * const kRNBlurDidShowNotification = @"com.whoisryannystrom.RNBlurModalView.show"; NSString * const kRNBlurDidHidewNotification = @"com.whoisryannystrom.RNBlurModalView.hide"; From 7b4166f90a9b7e5f8890a6ca3302ebee154c8f54 Mon Sep 17 00:00:00 2001 From: Raul Uranga Date: Thu, 8 Aug 2013 20:04:47 -0500 Subject: [PATCH 2/4] added functionality to dismiss when touching outside. --- RNBlurModalView.h | 3 ++- RNBlurModalView.m | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/RNBlurModalView.h b/RNBlurModalView.h index b5d39ef..c27e493 100644 --- a/RNBlurModalView.h +++ b/RNBlurModalView.h @@ -35,7 +35,7 @@ extern CGFloat kRNBlurBounceOutDurationScale; extern NSString * const kRNBlurDidShowNotification; extern NSString * const kRNBlurDidHidewNotification; -@interface RNBlurModalView : UIView +@interface RNBlurModalView : UIView @property (assign, readonly) BOOL isVisible; @@ -43,6 +43,7 @@ extern NSString * const kRNBlurDidHidewNotification; @property (assign) CGFloat animationDelay; @property (assign) UIViewAnimationOptions animationOptions; @property (assign) BOOL dismissButtonRight; +@property (nonatomic) BOOL tapOutsideToDismiss; @property (nonatomic, copy) void (^defaultHideBlock)(void); - (id)initWithViewController:(UIViewController*)viewController view:(UIView*)view; diff --git a/RNBlurModalView.m b/RNBlurModalView.m index db75f66..e98d983 100644 --- a/RNBlurModalView.m +++ b/RNBlurModalView.m @@ -146,6 +146,8 @@ - (id)initWithFrame:(CGRect)frame { _dismissButton.center = CGPointZero; [_dismissButton addTarget:self action:@selector(hide) forControlEvents:UIControlEventTouchUpInside]; + self.tapOutsideToDismiss = YES; + self.alpha = 0.f; self.backgroundColor = [UIColor clearColor]; // self.backgroundColor = [UIColor redColor]; @@ -158,6 +160,11 @@ - (id)initWithFrame:(CGRect)frame { UIViewAutoresizingFlexibleTopMargin); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChangeNotification:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; + + UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; + [singleTap setDelegate:self]; + [singleTap setNumberOfTapsRequired:1]; + [self addGestureRecognizer:singleTap]; } return self; } @@ -383,6 +390,16 @@ -(void)hideCloseButton:(BOOL)hide { [_dismissButton setHidden:hide]; } +-(void) handleTap:(UITapGestureRecognizer *) recognizer { + if(self.tapOutsideToDismiss){ + [self hide]; + } +} + +-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { + return !(touch.view == _contentView || touch.view == _dismissButton); +} + @end #pragma mark - RNBlurView From bd7e2569faf0b630333d485da03699d974e7238a Mon Sep 17 00:00:00 2001 From: Raul Uranga Date: Thu, 8 Aug 2013 22:16:48 -0500 Subject: [PATCH 3/4] added offsetX & offsetY properties to change view location. --- RNBlurModalView.h | 2 ++ RNBlurModalView.m | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/RNBlurModalView.h b/RNBlurModalView.h index c27e493..f009e3a 100644 --- a/RNBlurModalView.h +++ b/RNBlurModalView.h @@ -45,6 +45,8 @@ extern NSString * const kRNBlurDidHidewNotification; @property (assign) BOOL dismissButtonRight; @property (nonatomic) BOOL tapOutsideToDismiss; @property (nonatomic, copy) void (^defaultHideBlock)(void); +@property (assign) CGFloat offsetX; +@property (assign) CGFloat offsetY; - (id)initWithViewController:(UIViewController*)viewController view:(UIView*)view; - (id)initWithViewController:(UIViewController*)viewController title:(NSString*)title message:(NSString*)message; diff --git a/RNBlurModalView.m b/RNBlurModalView.m index e98d983..d88686e 100644 --- a/RNBlurModalView.m +++ b/RNBlurModalView.m @@ -175,7 +175,7 @@ - (id)initWithViewController:(UIViewController*)viewController view:(UIView*)vie if (self = [self initWithFrame:CGRectMake(0, 0, viewController.view.width, viewController.view.height)]) { [self addSubview:view]; _contentView = view; - _contentView.center = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)); + _contentView.center = CGPointMake(CGRectGetMidX(self.frame) - self.offsetX, CGRectGetMidY(self.frame) - self.offsetY); _controller = viewController; _parentView = nil; _contentView.clipsToBounds = YES; @@ -200,7 +200,7 @@ - (id)initWithParentView:(UIView*)parentView view:(UIView*)view { if (self = [self initWithFrame:CGRectMake(0, 0, parentView.width, parentView.height)]) { [self addSubview:view]; _contentView = view; - _contentView.center = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)); + _contentView.center = CGPointMake(CGRectGetMidX(self.frame) - self.offsetX, CGRectGetMidY(self.frame) - self.offsetY); _controller = nil; _parentView = parentView; _contentView.clipsToBounds = YES; @@ -279,8 +279,8 @@ - (void)updateSubviews { self.hidden = NO; - - _contentView.center = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)); + + _contentView.center = CGPointMake(CGRectGetMidX(self.frame) - self.offsetX, CGRectGetMidY(self.frame) - self.offsetY); _dismissButton.center = _contentView.origin; } @@ -335,6 +335,9 @@ - (void)delayedShow { [_parentView insertSubview:_blurView belowSubview:self]; } + + _contentView.center = CGPointMake(CGRectGetMidX(self.frame) - self.offsetX, CGRectGetMidY(self.frame) - self.offsetY); + _dismissButton.center = _contentView.origin; self.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.4, 0.4); [UIView animateWithDuration:self.animationDuration animations:^{ From 535c68289f0917bbbbefa16e87e08de171b15618 Mon Sep 17 00:00:00 2001 From: Raul Uranga Date: Mon, 12 Aug 2013 20:50:13 -0500 Subject: [PATCH 4/4] added startTransform & endTransform properties. --- RNBlurModalView.h | 3 +++ RNBlurModalView.m | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/RNBlurModalView.h b/RNBlurModalView.h index f009e3a..e398c8e 100644 --- a/RNBlurModalView.h +++ b/RNBlurModalView.h @@ -47,6 +47,9 @@ extern NSString * const kRNBlurDidHidewNotification; @property (nonatomic, copy) void (^defaultHideBlock)(void); @property (assign) CGFloat offsetX; @property (assign) CGFloat offsetY; +@property (nonatomic, assign) CGAffineTransform startTransform; +@property (nonatomic, assign) CGAffineTransform endTransform; + - (id)initWithViewController:(UIViewController*)viewController view:(UIView*)view; - (id)initWithViewController:(UIViewController*)viewController title:(NSString*)title message:(NSString*)message; diff --git a/RNBlurModalView.m b/RNBlurModalView.m index d88686e..7900f7e 100644 --- a/RNBlurModalView.m +++ b/RNBlurModalView.m @@ -139,7 +139,6 @@ + (UIView*)generateModalViewWithTitle:(NSString*)title message:(NSString*)messag return view; } - - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { _dismissButton = [[RNCloseButton alloc] init]; @@ -165,6 +164,9 @@ - (id)initWithFrame:(CGRect)frame { [singleTap setDelegate:self]; [singleTap setNumberOfTapsRequired:1]; [self addGestureRecognizer:singleTap]; + + self.startTransform = CGAffineTransformScale(CGAffineTransformIdentity, 0.4, 0.4); + self.endTransform = CGAffineTransformScale(CGAffineTransformIdentity, 1.f, 1.f); } return self; } @@ -339,7 +341,8 @@ - (void)delayedShow { _contentView.center = CGPointMake(CGRectGetMidX(self.frame) - self.offsetX, CGRectGetMidY(self.frame) - self.offsetY); _dismissButton.center = _contentView.origin; - self.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.4, 0.4); + self.transform = self.startTransform; + [UIView animateWithDuration:self.animationDuration animations:^{ _blurView.alpha = 1.f; self.alpha = 1.f; @@ -372,6 +375,7 @@ - (void)hideWithDuration:(CGFloat)duration delay:(NSTimeInterval)delay options:( animations:^{ self.alpha = 0.f; _blurView.alpha = 0.f; + self.transform = self.endTransform; } completion:^(BOOL finished){ if (finished) {