Skip to content

Instantly share code, notes, and snippets.

@albertodebortoli
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save albertodebortoli/9156276 to your computer and use it in GitHub Desktop.

Select an option

Save albertodebortoli/9156276 to your computer and use it in GitHub Desktop.
Blur the Facebook Profile image retrieved with the Facebook SDK
self.profilePictureView.profileID = user.id;
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
UIImageView *imageView = nil;
for (UIView *subview in [self.profilePictureView subviews]) {
if ([subview isKindOfClass:[UIImageView class]]) {
imageView = (UIImageView *)subview;
}
}
if (imageView) {
__block NSUInteger blurAppliedCount = 0;
_workingQueue = dispatch_queue_create("com.albertodebortoli.iWillDie", DISPATCH_QUEUE_SERIAL);
__weak dispatch_queue_t weakWorkingQueue = _workingQueue;
__weak typeof(self) weakSelf = self;
CGFloat blurValue = 0.1f;
self.blurRecursiveBlock = ^{
if (blurAppliedCount < 100) {
blurAppliedCount++;
UIImage *blurredImage = [imageView.image blurredImageWithRadius:blurValue];
dispatch_async(dispatch_get_main_queue(), ^{
imageView.image = blurredImage;
double delayInSeconds = 0.01;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, weakWorkingQueue, weakSelf.blurRecursiveBlock);
});
}
};
dispatch_async(_workingQueue, self.blurRecursiveBlock);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment