Skip to content
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.

Made updateBlur public, added updateBlurInterval #7

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
122 changes: 0 additions & 122 deletions Demo/SVBlurView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,12 @@
22EF1083181325A900CDF72C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 22EF1081181325A900CDF72C /* Main.storyboard */; };
22EF1086181325A900CDF72C /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 22EF1085181325A900CDF72C /* ViewController.m */; };
22EF1088181325A900CDF72C /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 22EF1087181325A900CDF72C /* Images.xcassets */; };
22EF108F181325AA00CDF72C /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22EF108E181325AA00CDF72C /* XCTest.framework */; };
22EF1090181325AA00CDF72C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22EF106F181325A900CDF72C /* Foundation.framework */; };
22EF1091181325AA00CDF72C /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22EF1073181325A900CDF72C /* UIKit.framework */; };
22EF10AA181326D600CDF72C /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 22EF10A9181326D600CDF72C /* [email protected] */; };
22EF10AE18132FD800CDF72C /* SVBlurView.m in Sources */ = {isa = PBXBuildFile; fileRef = 22EF10AD18132FD800CDF72C /* SVBlurView.m */; };
22EF10B01813311700CDF72C /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 22EF10AF1813311700CDF72C /* README.md */; };
22EF10BB181336AA00CDF72C /* UIImage+ImageEffects.m in Sources */ = {isa = PBXBuildFile; fileRef = 22EF10BA181336AA00CDF72C /* UIImage+ImageEffects.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
22EF1092181325AA00CDF72C /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 22EF1064181325A900CDF72C /* Project object */;
proxyType = 1;
remoteGlobalIDString = 22EF106B181325A900CDF72C;
remoteInfo = SVBlurView;
};
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
22EF106C181325A900CDF72C /* SVBlurView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SVBlurView.app; sourceTree = BUILT_PRODUCTS_DIR; };
22EF106F181325A900CDF72C /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand All @@ -50,7 +37,6 @@
22EF1084181325A900CDF72C /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
22EF1085181325A900CDF72C /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
22EF1087181325A900CDF72C /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
22EF108D181325AA00CDF72C /* SVBlurViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SVBlurViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
22EF108E181325AA00CDF72C /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
22EF10A9181326D600CDF72C /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
22EF10AC18132FD800CDF72C /* SVBlurView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVBlurView.h; sourceTree = "<group>"; };
Expand All @@ -71,16 +57,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
22EF108A181325AA00CDF72C /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
22EF108F181325AA00CDF72C /* XCTest.framework in Frameworks */,
22EF1091181325AA00CDF72C /* UIKit.framework in Frameworks */,
22EF1090181325AA00CDF72C /* Foundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
Expand All @@ -99,7 +75,6 @@
isa = PBXGroup;
children = (
22EF106C181325A900CDF72C /* SVBlurView.app */,
22EF108D181325AA00CDF72C /* SVBlurViewTests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -174,24 +149,6 @@
productReference = 22EF106C181325A900CDF72C /* SVBlurView.app */;
productType = "com.apple.product-type.application";
};
22EF108C181325AA00CDF72C /* SVBlurViewTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 22EF10A1181325AA00CDF72C /* Build configuration list for PBXNativeTarget "SVBlurViewTests" */;
buildPhases = (
22EF1089181325AA00CDF72C /* Sources */,
22EF108A181325AA00CDF72C /* Frameworks */,
22EF108B181325AA00CDF72C /* Resources */,
);
buildRules = (
);
dependencies = (
22EF1093181325AA00CDF72C /* PBXTargetDependency */,
);
name = SVBlurViewTests;
productName = SVBlurViewTests;
productReference = 22EF108D181325AA00CDF72C /* SVBlurViewTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
Expand All @@ -200,11 +157,6 @@
attributes = {
LastUpgradeCheck = 0500;
ORGANIZATIONNAME = "Sam Vermette";
TargetAttributes = {
22EF108C181325AA00CDF72C = {
TestTargetID = 22EF106B181325A900CDF72C;
};
};
};
buildConfigurationList = 22EF1067181325A900CDF72C /* Build configuration list for PBXProject "SVBlurView" */;
compatibilityVersion = "Xcode 3.2";
Expand All @@ -220,7 +172,6 @@
projectRoot = "";
targets = (
22EF106B181325A900CDF72C /* SVBlurView */,
22EF108C181325AA00CDF72C /* SVBlurViewTests */,
);
};
/* End PBXProject section */
Expand All @@ -238,13 +189,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
22EF108B181325AA00CDF72C /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand All @@ -260,23 +204,8 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
22EF1089181325AA00CDF72C /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
22EF1093181325AA00CDF72C /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 22EF106B181325A900CDF72C /* SVBlurView */;
targetProxy = 22EF1092181325AA00CDF72C /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
22EF1078181325A900CDF72C /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
Expand Down Expand Up @@ -395,48 +324,6 @@
};
name = Release;
};
22EF10A2181325AA00CDF72C /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/SVBlurView.app/SVBlurView";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
"$(DEVELOPER_FRAMEWORKS_DIR)",
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SVBlurView/SVBlurView-Prefix.pch";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
INFOPLIST_FILE = "SVBlurViewTests/SVBlurViewTests-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = xctest;
};
name = Debug;
};
22EF10A3181325AA00CDF72C /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/SVBlurView.app/SVBlurView";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
"$(DEVELOPER_FRAMEWORKS_DIR)",
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SVBlurView/SVBlurView-Prefix.pch";
INFOPLIST_FILE = "SVBlurViewTests/SVBlurViewTests-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = xctest;
};
name = Release;
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
Expand All @@ -458,15 +345,6 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
22EF10A1181325AA00CDF72C /* Build configuration list for PBXNativeTarget "SVBlurViewTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
22EF10A2181325AA00CDF72C /* Debug */,
22EF10A3181325AA00CDF72C /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 22EF1064181325A900CDF72C /* Project object */;
Expand Down
16 changes: 15 additions & 1 deletion Demo/SVBlurView/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,22 @@ - (void)viewDidLoad {
backgroundView.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:backgroundView];

UILabel *helloLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 60, 200, 20)];
helloLabel.text = @"SVBlurView";
helloLabel.textColor = [UIColor redColor];
helloLabel.textAlignment = NSTextAlignmentCenter;
helloLabel.font = [UIFont boldSystemFontOfSize:20.f];
[backgroundView addSubview:helloLabel];

[UIView animateWithDuration:5 delay:0 options:UIViewAnimationOptionAutoreverse|UIViewAnimationOptionRepeat animations:^{
helloLabel.frame = CGRectMake(60, 320, 200, 20);
} completion:nil];

SVBlurView *blurView = [[SVBlurView alloc] initWithFrame:CGRectMake(60, 100, 200, 200)];
[backgroundView addSubview:blurView];
blurView.blurRadius = 5.f;
blurView.updateBlurInterval = 1.f/60; //60 fps
blurView.viewToBlur = backgroundView;
[self.view addSubview:blurView];
}

@end
3 changes: 3 additions & 0 deletions SVBlurView/SVBlurView.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
@property (nonatomic, readwrite) CGFloat saturationDelta; // default is 1.5
@property (nonatomic, readwrite) UIColor *tintColor; // default nil
@property (nonatomic, weak) UIView *viewToBlur; // default is superview
@property (nonatomic, assign) float updateBlurInterval; //default is 0

- (void) updateBlur;

@end
52 changes: 46 additions & 6 deletions SVBlurView/SVBlurView.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,43 @@

@interface SVBlurView ()

@property (nonatomic, strong) dispatch_source_t updateBlurTimer;

@end


@implementation SVBlurView

- (id)init {
if(self = [super init]) {
[self setUp];
}
return self;
}

- (id)initWithFrame:(CGRect)frame {
if(self = [super initWithFrame:frame]) {
self.blurRadius = 20;
self.saturationDelta = 1.5;
self.tintColor = nil;
self.viewToBlur = nil;
self.clipsToBounds = YES;
[self setUp];
}
return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder {
if(self = [super initWithCoder:aDecoder]) {
[self setUp];
}
return self;
}

- (void)setUp {
self.blurRadius = 20;
self.saturationDelta = 1.5;
self.tintColor = nil;
self.viewToBlur = nil;
self.updateBlurInterval = 0;
self.clipsToBounds = YES;
}

- (void)encodeRestorableStateWithCoder:(NSCoder *)coder {
[super encodeRestorableStateWithCoder:coder];

Expand All @@ -47,9 +68,28 @@ - (UIView *)viewToBlur {
return self.superview;
}

- (void)setUpdateBlurInterval:(float)updateBlurInterval {
self.updateBlurTimer = (_updateBlurInterval=updateBlurInterval)>0?CreateDispatchTimer(_updateBlurInterval*NSEC_PER_SEC, 1ull*NSEC_PER_SEC, dispatch_get_main_queue(), ^{ [self updateBlur]; }):nil;
}

- (void)setUpdateBlurTimer:(dispatch_source_t)updateBlurTimer {
if(_updateBlurTimer) dispatch_source_cancel(_updateBlurTimer);
if((_updateBlurTimer=updateBlurTimer))
dispatch_resume(_updateBlurTimer);
}

dispatch_source_t CreateDispatchTimer(uint64_t interval, uint64_t leeway, dispatch_queue_t queue, dispatch_block_t block) {
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
if (timer) {
dispatch_source_set_timer(timer, dispatch_walltime(NULL, 0), interval, leeway);
dispatch_source_set_event_handler(timer, block);
}
return timer;
}

- (void)updateBlur {
UIGraphicsBeginImageContextWithOptions(self.viewToBlur.bounds.size, NO, 0.0);
[self.viewToBlur drawViewHierarchyInRect:self.viewToBlur.bounds afterScreenUpdates:YES];
[self.viewToBlur drawViewHierarchyInRect:self.viewToBlur.bounds afterScreenUpdates:NO];
UIImage *complexViewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Expand Down