From ecbcee4e2a871436784e0519c329bfb8804da902 Mon Sep 17 00:00:00 2001 From: omer ozkul Date: Mon, 19 Oct 2015 21:10:10 +0200 Subject: [PATCH] - add blur radius property on MCPanelViewController to be able to control the blur effect on the MCPanel. - fix warnings on MCPanGestureRecognizer ("abs" was not adapted for Float value) --- .../MCPanGestureRecognizer.m | 4 +- MCPanelViewController/MCPanelViewController.h | 7 +++- MCPanelViewController/MCPanelViewController.m | 17 ++++++++ MCPanelViewController/UIImage+ImageEffects.h | 5 +++ MCPanelViewController/UIImage+ImageEffects.m | 41 +++++++++++++++---- 5 files changed, 64 insertions(+), 10 deletions(-) diff --git a/MCPanelViewController/MCPanGestureRecognizer.m b/MCPanelViewController/MCPanGestureRecognizer.m index fbe8691..e2dbf82 100644 --- a/MCPanelViewController/MCPanGestureRecognizer.m +++ b/MCPanelViewController/MCPanGestureRecognizer.m @@ -26,11 +26,11 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { _translationY += prevPoint.y - nowPoint.y; if (!_isDragging) { if (_direction == MCPanGestureRecognizerDirectionHorizontal && - abs(_translationY) > MCPanGestureRecognizerThreshold) { + fabs(_translationY) > MCPanGestureRecognizerThreshold) { self.state = UIGestureRecognizerStateFailed; } if (_direction == MCPanGestureRecognizerDirectionVertical && - abs(_translationX) > MCPanGestureRecognizerThreshold) { + fabs(_translationX) > MCPanGestureRecognizerThreshold) { self.state = UIGestureRecognizerStateFailed; } _isDragging = YES; diff --git a/MCPanelViewController/MCPanelViewController.h b/MCPanelViewController/MCPanelViewController.h index 69b3337..909c1e1 100644 --- a/MCPanelViewController/MCPanelViewController.h +++ b/MCPanelViewController/MCPanelViewController.h @@ -17,7 +17,11 @@ typedef NS_ENUM(NSInteger, MCPanelBackgroundStyle) { MCPanelBackgroundStyleLight = 0, MCPanelBackgroundStyleExtraLight, MCPanelBackgroundStyleDark, - MCPanelBackgroundStyleTinted + MCPanelBackgroundStyleTinted, + MCPanelBackgroundStyleLightCustomBlurRadius, + MCPanelBackgroundStyleExtraLightCustomBlurRadius, + MCPanelBackgroundStyleDarkCustomBlurRadius, + MCPanelBackgroundStyleTintedCustomBlurRadius }; @class MCPanelViewController; @@ -38,6 +42,7 @@ typedef NS_ENUM(NSInteger, MCPanelBackgroundStyle) { @property (assign, nonatomic) CGFloat shadowOpacity; @property (assign, nonatomic) CGFloat shadowRadius; @property (assign, nonatomic) MCPanelBackgroundStyle backgroundStyle; +@property (assign, nonatomic) CGFloat blurRadius; // use to customize the blur radius of the MCPanel @property (assign, nonatomic, getter = isMasking) BOOL masking; @property (assign, nonatomic, getter = isPanningEnabled) BOOL panningEnabled; @property (weak, nonatomic) id delegate; diff --git a/MCPanelViewController/MCPanelViewController.m b/MCPanelViewController/MCPanelViewController.m index 1a5af1e..9d4ccec 100644 --- a/MCPanelViewController/MCPanelViewController.m +++ b/MCPanelViewController/MCPanelViewController.m @@ -86,6 +86,7 @@ - (id)initWithRootViewController:(UIViewController *)controller { self.tintColor = [UIColor colorWithWhite:1.0 alpha:0.3]; self.maskColor = [UIColor colorWithWhite:0 alpha:0.5]; self.shadowColor = [UIColor blackColor]; + self.blurRadius = 0; self.shadowOpacity = 0.3; self.shadowRadius = 5; self.rootViewController = controller; @@ -361,6 +362,22 @@ - (void)refreshBackgroundAnimated:(BOOL)animated { case MCPanelBackgroundStyleTinted: image = [image applyTintEffectWithColor:self.tintColor]; break; + + case MCPanelBackgroundStyleLightCustomBlurRadius: + image = [image applyLightEffectWithBlurRadius:self.blurRadius]; + break; + + case MCPanelBackgroundStyleExtraLightCustomBlurRadius: + image = [image applyExtraLightEffectWithBlurRadius:self.blurRadius]; + break; + + case MCPanelBackgroundStyleDarkCustomBlurRadius: + image = [image applyDarkEffectWithBlurRadius:self.blurRadius]; + break; + + case MCPanelBackgroundStyleTintedCustomBlurRadius: + image = [image applyTintEffectWithColor:self.tintColor blurRadius:self.blurRadius]; + break; default: image = [image applyLightEffect]; diff --git a/MCPanelViewController/UIImage+ImageEffects.h b/MCPanelViewController/UIImage+ImageEffects.h index d92790d..15838c2 100644 --- a/MCPanelViewController/UIImage+ImageEffects.h +++ b/MCPanelViewController/UIImage+ImageEffects.h @@ -102,6 +102,11 @@ - (UIImage *)applyDarkEffect; - (UIImage *)applyTintEffectWithColor:(UIColor *)tintColor; +- (UIImage *)applyLightEffectWithBlurRadius:(CGFloat)blurRadius; +- (UIImage *)applyExtraLightEffectWithBlurRadius:(CGFloat)blurRadius; +- (UIImage *)applyDarkEffectWithBlurRadius:(CGFloat)blurRadius; +- (UIImage *)applyTintEffectWithColor:(UIColor *)tintColor blurRadius:(CGFloat)blurRadius; + - (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage; @end diff --git a/MCPanelViewController/UIImage+ImageEffects.m b/MCPanelViewController/UIImage+ImageEffects.m index f35d01c..c961131 100644 --- a/MCPanelViewController/UIImage+ImageEffects.m +++ b/MCPanelViewController/UIImage+ImageEffects.m @@ -101,29 +101,56 @@ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF @implementation UIImage (ImageEffects) +#pragma mark - effect method with default value for predifined blur radius - (UIImage *)applyLightEffect { - UIColor *tintColor = [UIColor colorWithWhite:1.0 alpha:0.3]; - return [self applyBlurWithRadius:30 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil]; + return [self applyLightEffectWithBlurRadius:30]; } - (UIImage *)applyExtraLightEffect { - UIColor *tintColor = [UIColor colorWithWhite:0.97 alpha:0.82]; - return [self applyBlurWithRadius:20 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil]; + return [self applyExtraLightEffectWithBlurRadius:20]; } - (UIImage *)applyDarkEffect { - UIColor *tintColor = [UIColor colorWithWhite:0.11 alpha:0.73]; - return [self applyBlurWithRadius:20 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil]; + return [self applyDarkEffectWithBlurRadius:20]; } - (UIImage *)applyTintEffectWithColor:(UIColor *)tintColor +{ + return [self applyTintEffectWithColor:tintColor blurRadius:10]; +} + + +#pragma mark - effect method with custom blur radius + + +- (UIImage *)applyLightEffectWithBlurRadius:(CGFloat)blurRadius +{ + UIColor *tintColor = [UIColor colorWithWhite:1.0 alpha:0.3]; + return [self applyBlurWithRadius:blurRadius tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil]; +} + +- (UIImage *)applyExtraLightEffectWithBlurRadius:(CGFloat)blurRadius +{ + UIColor *tintColor = [UIColor colorWithWhite:0.97 alpha:0.82]; + return [self applyBlurWithRadius:blurRadius tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil]; +} + + +- (UIImage *)applyDarkEffectWithBlurRadius:(CGFloat)blurRadius +{ + UIColor *tintColor = [UIColor colorWithWhite:0.11 alpha:0.73]; + return [self applyBlurWithRadius:blurRadius tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil]; +} + + +- (UIImage *)applyTintEffectWithColor:(UIColor *)tintColor blurRadius:(CGFloat)blurRadius { const CGFloat EffectColorAlpha = 0.6; UIColor *effectColor = tintColor; @@ -140,7 +167,7 @@ - (UIImage *)applyTintEffectWithColor:(UIColor *)tintColor effectColor = [UIColor colorWithRed:r green:g blue:b alpha:EffectColorAlpha]; } } - return [self applyBlurWithRadius:10 tintColor:effectColor saturationDeltaFactor:-1.0 maskImage:nil]; + return [self applyBlurWithRadius:blurRadius tintColor:effectColor saturationDeltaFactor:-1.0 maskImage:nil]; }