Created
November 22, 2014 09:02
-
-
Save lonkly/d2b0ecfd75e748588c17 to your computer and use it in GitHub Desktop.
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
#pragma mark Helpers | |
- (void)blurIn | |
{ | |
if (_bluringTimer) | |
return; | |
GPUImageiOSBlurFilter *blurFilter = [[GPUImageiOSBlurFilter alloc] init]; | |
if ([[blurFilter targets] count] == 0) | |
{ | |
blurFilter.blurRadiusInPixels = 0.0f; | |
blurFilter.saturation = 1.4; | |
blurFilter.downsampling = 8; | |
self.cameraView.currentFilter = (GPUImageFilter*)blurFilter; | |
} | |
_bluringTimer = [NSTimer timerWithTimeInterval:0.01 | |
target:self | |
selector:@selector(blurTimerStep:) | |
userInfo:@(YES) | |
repeats:YES]; | |
[[NSRunLoop mainRunLoop] addTimer:_bluringTimer forMode:NSRunLoopCommonModes]; | |
} | |
- (void)blurOut | |
{ | |
if (_bluringTimer) | |
return; | |
_bluringTimer = [NSTimer timerWithTimeInterval:0.025 | |
target:self | |
selector:@selector(blurTimerStep:) | |
userInfo:@(NO) | |
repeats:YES]; | |
[[NSRunLoop mainRunLoop] addTimer:_bluringTimer forMode:NSRunLoopCommonModes]; | |
} | |
- (void)blurTimerStep:(NSTimer *)timer | |
{ | |
static NSInteger Step; | |
BOOL blurringIn = [[timer userInfo] boolValue]; | |
static CGFloat MaxBlur = 16.0f; | |
CGFloat bluringStepsCount = 10; | |
CGFloat blurSizeStep = MaxBlur/bluringStepsCount; | |
((GPUImageiOSBlurFilter*)self.cameraView.currentFilter).blurRadiusInPixels += (blurringIn ? blurSizeStep : -blurSizeStep); | |
Step++; | |
if (Step > bluringStepsCount) | |
{ | |
[_bluringTimer invalidate]; | |
_bluringTimer = nil; | |
Step = 0; | |
if (!blurringIn) | |
[self.cameraView restoreCameraOptions]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment