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