效果图
代码 // // ViewController.m // UImage+ImageEffects-Demo // // Created by 寒竹子 on 15/6/14. // Copyright (c) 2015年 寒竹子. All rights reserved. // #import "ViewController.h" #import "GCD.h" #import "UIImage+ImageEffects.h" @interface ViewController () @property (nonatomic, strong) UIImageView * imageView; @property (nonatomic) UIViewContentMode contentMode; // 图片显示的模式 @end @implementation ViewController - (instancetype)init { if (self = [super init]) { // Initial code }
return self; } @synthesize contentMode = _contentMode; #pragma mark - getter and setter - (void)setContentMode:(UIViewContentMode)contentMode { _contentMode = contentMode; self.imageView.contentMode = contentMode; } - (UIViewContentMode)contentMode { return _contentMode; } - (void)viewDidLoad { [super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; self.imageView.alpha = .0f; self.imageView.center = self.view.center; self.contentMode = UIViewContentModeScaleAspectFill; [self.view addSubview:self.imageView];
// 异步下载图片 [GCDQueue executeInGlobalQueue:^{ NSString * imageURL = @"http://www.huabian.com/uploadfile/2014/1229/20141229033638152.jpg"; NSURLRequest * urlRequest = [NSURLRequest requestWithURL:[NSURLURLWithString:imageURL]]; // 下载图片 NSData * imageData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:nil error:nil]; UIImage * image = [UIImage imageWithData:imageData];
// 模糊图片 并设置模糊程度 UIImage * blurImage = [image blurImageWithRadius:10.0f];
// 主线程 更新UI [GCDQueue executeInMainQueue:^{ self.imageView.image = blurImage; [UIView animateWithDuration:1.0f animations:^{ self.imageView.alpha = 1.0f; } completion:nil]; }]; }]; } @end |