【发布时间】:2021-01-23 03:03:24
【问题描述】:
stop 机制在这段代码中是如何工作的?
@interface GifAnaimator()
@property BOOL stopping;
@end
@implementation GifAnaimator
- (void)startWithURL:(CFURLRef)imageURL {
__weak GifAnaimator *weakSelf = self;
CGAnimateImageAtURLWithBlock(imageURL, nil, ^(size_t index, CGImageRef image, bool* stop) {
// Some image handling code...
*stop = weakSelf.stopping;
});
}
- (void)stop {
self.stopping = YES;
}
@end
这段代码让我感到困惑的是,取消引用的stop 被分配了一个普通的、非指向的BOOL、stopping。之后,当stopping 发生突变时,stop 会以某种方式得到相同的突变。
我尝试在一个块中捕获stop,然后稍后调用该块来改变它,如下所示:
weakSelf.stopAnimation = ^{
*stop = YES;
};
这段代码对我来说更有意义,但它不起作用。
这里到底发生了什么?
【问题讨论】:
标签: c objective-c pointers primitive