我正在查看 IOS7 Programming Pushing the Limits 一书中的以下代码,并且无法理解为什么作者在不使用块的情况下使用了__block
存储类型。我对__block
的了解仅限于理解它们允许块中范围内捕获的变量是可变的。我已经阅读了一些关于__block
的其他SO帖子,但他们更加困惑我。
-(IBAction)buttonAction:(id)sender {
self.layer = [CALayer layer];
self.layer.frame = CGRectMake(80, 100, 160, 160);
[self.view.layer addSublayer:self.layer];
float scale = [UIScreen mainScreen].scale;
UIGraphicsBeginImageContextWithOptions(self.view.frame.size, YES, scale);
[self.view drawViewHierarchyInRect:self.view.frame afterScreenUpdates:NO];
__block UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef imageRef = CGImageCreateWithImageInRect(image.CGImage,
CGRectMake(self.layer.frame.origin.x * scale,
self.layer.frame.origin.y * scale,
self.layer.frame.size.width * scale,
self.layer.frame.size.height * scale));
image = [UIImage imageWithCGImage:imageRef];
image = [image applyBlurWithRadius:50.0f
tintColor:[UIColor colorWithRed:0 green:1 blue:0 alpha:0.1]
saturationDeltaFactor:2.0f
maskImage:nil];
self.layer.contents = (__bridge id)(image.CGImage);
}
答案 0 :(得分:1)
我的猜测是编辑错误。代码可能在某一点上包含了一个块,但它在稍后的编辑中被删除了,但是作者忘了带走__block限定符。