在UIView animateWithDuration中取消阻止

Ric*_*kiG 4 cocoa-touch objective-c-blocks

- (void) startLoading {

    [self blink];
} 

 - (void) blink {  

        [UIView animateWithDuration:0.5
                              delay: 0.0
                            options: UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveEaseOut
                         animations:^{
                            //animate stuff
                         }
                         completion:^(BOOL finished){
                                 [self blink];    
                         }];

}

- (void) stopLoading {
    //What goes here?
}
Run Code Online (Sandbox Code Playgroud)

在我的UIView中initWithFrame,我构建了一些加载器图形然后从中启动加载器动画[self startLoading].

现在的问题是,如何阻止这种"无限循环"?或者什么是stopLoading或dealloc方法,以便很好地撕下一切?

当我忽略了一个完成块就在那里并从超级视图中释放我的UIView的事实时,一切都会好几秒钟(超过指定的0.5秒)然后应用程序崩溃并显示一条消息:

malloc:*mmap(size = 2097152)失败(错误代码= 12) 错误:无法分配区域**在malloc_error_break中设置断点进行调试

我在malloc_error_break中有一个断点,罪魁祸首是动画块.

我假设UIView是通过从超级视图中删除而被释放的,之后执行完成块,self对此的引用是对已发布的对象进行消息传递.

我在文档中找不到有关取消"排队"块的任何内容.

mat*_*att 7

要取消,请执行您希望能够取消的任何循环操作的操作:设置每次循环前检查的标志.所以:

- (void) stopLoading {
    kCancel = YES;
}
Run Code Online (Sandbox Code Playgroud)

现在你的完成块看起来像这样:

completion:^(BOOL finished){
    if (!kCancel)
        [self blink];    
}];
Run Code Online (Sandbox Code Playgroud)

kCancel 可能是一个ivar,一个静态的全局变量,无论如何.