NSOperationQueue 设置依赖

前端之家收集整理的这篇文章主要介绍了NSOperationQueue 设置依赖前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

NSOperationQueue*queue=[[NSOperationQueue alloc]init];

NSBlockOperation*blockOperation=[NSBlockOperation blockOperationWithBlock:^{

NSURL *url = [NSURL URLWithString:@"http://img.pconline.com.cn/images/photoblog/9/9/8/1/9981681/200910/11/1255259355826.jpg"];

NSData*data=[NSData dataWithContentsOfURL:url];

[[NSOperationQueue mainQueue] addOperationWithBlock:^{

self.singleImageView.image=[UIImage imageWithData:data];

}];

}];

NSBlockOperation*blockOperation1=[NSBlockOperation blockOperationWithBlock:^{

NSURL *url = [NSURL URLWithString:@"http://img.pconline.com.cn/images/photoblog/9/9/8/1/9981681/200910/11/1255259355826.jpg"];

NSData*data=[NSData dataWithContentsOfURL:url];

[[NSOperationQueue mainQueue] addOperationWithBlock:^{

self.secondImageView.image=[UIImage imageWithData:data];

}];

}];

__weak __typeof__(self) weakSelf = self;

NSBlockOperation*blockOperation3=[NSBlockOperation blockOperationWithBlock:^{

UIGraphicsBeginImageContext(self.bottomImageView.frame.size);

CGSize size= self.bottomImageView.frame.size;

[weakSelf.singleImageView.image drawInRect:CGRectMake(0,size.width/2,size.height)];

[weakSelf.secondImageView.image drawInRect:CGRectMake(size.width/2,size.height)];

UIImage *finalImage=UIGraphicsGetImageFromCurrentImageContext();

[[NSOperationQueue mainQueue] addOperationWithBlock:^{

weakSelf.bottomImageView.image=finalImage;

}];

UIGraphicsEndImageContext();

}];

[blockOperation3 addDependency:blockOperation1];

[blockOperation3 addDependency:blockOperation];


[queue addOperation:blockOperation3];

[queue addOperation:blockOperation1];

[queue addOperation:blockOperation];

原文链接:https://www.f2er.com/javaschema/283761.html

猜你在找的设计模式相关文章