__block存储类型没有块?

时间:2014-10-29 21:43:30

标签: ios objective-c objective-c-blocks

我正在查看 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);
}

1 个答案:

答案 0 :(得分:1)

我的猜测是编辑错误。代码可能在某一点上包含了一个块,但它在稍后的编辑中被删除了,但是作者忘了带走__block限定符。