Last active
August 29, 2015 13:56
-
-
Save albertodebortoli/9156276 to your computer and use it in GitHub Desktop.
Blur the Facebook Profile image retrieved with the Facebook SDK
This file contains hidden or 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
| 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