Skip to content

Instantly share code, notes, and snippets.

@kenshin03
Created May 1, 2013 08:03
Show Gist options
  • Save kenshin03/5494256 to your computer and use it in GitHub Desktop.
Save kenshin03/5494256 to your computer and use it in GitHub Desktop.
ascync loading background image and extracting its background color with LEColorPicker
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if (!self.imageURLString){
self.imageURLString = self.sourceAvartarImageURL;
self.backgroundImageView.contentMode = UIViewContentModeScaleAspectFill;
}
UIImage * feedImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.imageURLString]]];
dispatch_async(dispatch_get_main_queue(), ^{
self.backgroundImageView.alpha = 0.0f;
self.backgroundImageView.image = feedImage;
[LEColorPicker pickColorFromImage:feedImage onComplete:^(NSDictionary *colorsPickedDictionary) {
[UIView beginAnimations:@"ColorChange" context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
self.view.backgroundColor = colorsPickedDictionary[@"BackgroundColor"];
[UIView commitAnimations];
}];
[UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.backgroundImageView.alpha = 1.0f;
} completion:^(BOOL finished) {
}];
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment