Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add blurRadius property for blur effect and fix warnings #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions MCPanelViewController/MCPanGestureRecognizer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion MCPanelViewController/MCPanelViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ typedef NS_ENUM(NSInteger, MCPanelBackgroundStyle) {
MCPanelBackgroundStyleLight = 0,
MCPanelBackgroundStyleExtraLight,
MCPanelBackgroundStyleDark,
MCPanelBackgroundStyleTinted
MCPanelBackgroundStyleTinted,
MCPanelBackgroundStyleLightCustomBlurRadius,
MCPanelBackgroundStyleExtraLightCustomBlurRadius,
MCPanelBackgroundStyleDarkCustomBlurRadius,
MCPanelBackgroundStyleTintedCustomBlurRadius
};

@class MCPanelViewController;
Expand All @@ -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<MCPanelViewControllerDelegate> delegate;
Expand Down
17 changes: 17 additions & 0 deletions MCPanelViewController/MCPanelViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
5 changes: 5 additions & 0 deletions MCPanelViewController/UIImage+ImageEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 34 additions & 7 deletions MCPanelViewController/UIImage+ImageEffects.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];
}


Expand Down