This repository has been archived by the owner on Mar 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
192 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// CKBlurView.h | ||
// CKBlurView | ||
// | ||
// Created by Conrad Kramer on 10/25/13. | ||
// Copyright (c) 2013 Kramer Software Productions, LLC. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import <QuartzCore/QuartzCore.h> | ||
#import <CoreGraphics/CoreGraphics.h> | ||
|
||
extern NSString * const CKBlurViewQualityDefault; | ||
|
||
extern NSString * const CKBlurViewQualityLow; | ||
|
||
NS_CLASS_AVAILABLE_IOS(7_0) @interface CKBlurView : UIView | ||
|
||
/** | ||
Quality of the blur. The lower the quality, the more performant the blur. Must be one of `CKBlurViewQualityDefault` or `CKBlurViewQualityLow`. Defaults to `CKBlurViewQualityDefault`. | ||
*/ | ||
@property (nonatomic, retain) NSString *blurQuality; | ||
|
||
/** | ||
Radius of the Gaussian blur. Defaults to 5.0. | ||
*/ | ||
@property (nonatomic, readwrite) CGFloat blurRadius; | ||
|
||
/** | ||
Bounds to be blurred, in the receiver's coordinate system. Defaults to CGRectNull. | ||
*/ | ||
@property (nonatomic, readwrite) CGRect blurCroppingRect; | ||
|
||
/** | ||
Boolean indicating whether the edge of the view should be softened. Defaults to YES. | ||
*/ | ||
@property (nonatomic, readwrite) BOOL blurEdges; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// | ||
// CKBlurView.m | ||
// CKBlurView | ||
// | ||
// Created by Conrad Kramer on 10/25/13. | ||
// Copyright (c) 2013 Kramer Software Productions, LLC. All rights reserved. | ||
// | ||
|
||
#import "CKBlurView.h" | ||
|
||
@interface CABackdropLayer : CALayer | ||
|
||
@end | ||
|
||
@interface CAFilter : NSObject | ||
|
||
+ (instancetype)filterWithName:(NSString *)name; | ||
|
||
@end | ||
|
||
@interface CKBlurView () | ||
|
||
@property (retain, nonatomic) CAFilter *blurFilter; | ||
|
||
@end | ||
|
||
extern NSString * const kCAFilterGaussianBlur; | ||
|
||
NSString * const CKBlurViewQualityDefault = @"default"; | ||
|
||
NSString * const CKBlurViewQualityLow = @"low"; | ||
|
||
static NSString * const CKBlurViewQualityKey = @"inputQuality"; | ||
|
||
static NSString * const CKBlurViewRadiusKey = @"inputRadius"; | ||
|
||
static NSString * const CKBlurViewBoundsKey = @"inputBounds"; | ||
|
||
static NSString * const CKBlurViewHardEdgesKey = @"inputHardEdges"; | ||
|
||
|
||
@implementation CKBlurView | ||
|
||
+ (Class)layerClass { | ||
return [CABackdropLayer class]; | ||
} | ||
|
||
- (instancetype)initWithFrame:(CGRect)frame { | ||
self = [super initWithFrame:frame]; | ||
if (self) { | ||
CAFilter *filter = [CAFilter filterWithName:kCAFilterGaussianBlur]; | ||
self.layer.filters = @[ filter ]; | ||
self.blurFilter = filter; | ||
|
||
self.blurQuality = CKBlurViewQualityDefault; | ||
self.blurRadius = 5.0f; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)setQuality:(NSString *)quality { | ||
[self.blurFilter setValue:quality forKey:CKBlurViewQualityKey]; | ||
} | ||
|
||
- (NSString *)quality { | ||
return [self.blurFilter valueForKey:CKBlurViewQualityKey]; | ||
} | ||
|
||
- (void)setBlurRadius:(CGFloat)radius { | ||
[self.blurFilter setValue:@(radius) forKey:CKBlurViewRadiusKey]; | ||
} | ||
|
||
- (CGFloat)blurRadius { | ||
return [[self.blurFilter valueForKey:CKBlurViewRadiusKey] floatValue]; | ||
} | ||
|
||
- (void)setBlurCroppingRect:(CGRect)croppingRect { | ||
[self.blurFilter setValue:[NSValue valueWithCGRect:croppingRect] forKey:CKBlurViewBoundsKey]; | ||
} | ||
|
||
- (CGRect)blurCroppingRect { | ||
NSValue *value = [self.blurFilter valueForKey:CKBlurViewBoundsKey]; | ||
return value ? [value CGRectValue] : CGRectNull; | ||
} | ||
|
||
- (void)setBlurEdges:(BOOL)blurEdges { | ||
[self.blurFilter setValue:@(!blurEdges) forKey:CKBlurViewHardEdgesKey]; | ||
} | ||
|
||
- (BOOL)blurEdges { | ||
return ![[self.blurFilter valueForKey:CKBlurViewHardEdgesKey] boolValue]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters