我们是否需要在ARC的UIAnimationBlocks中使用__weak self? [英] Do we need to use __weak self inside UIAnimationBlocks in ARC?

查看:227
本文介绍了我们是否需要在ARC的UIAnimationBlocks中使用__weak self?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们是否需要在UIAnimation Blocks中使用__weak self,如下所示?如果我们没有指定self为弱,是否会产生保留周期问题?

Do we need to use __weak self inside UIAnimation Blocks as given below? Whether it will create retain cycle issue if we are not specifying self as weak?

[UIView animateWithDuration:animationDuration 
                      delay:0 
                    options:UIViewAnimationCurveEaseInOut 
                 animations:^{
        [self doSomething];
    } completion:^(BOOL finished) {
        if (finished) {
            [self doSomething];
        }
    }];

我也对以下情况感到困惑。有什么想法吗?请分享您的意见。

I am also confused in the following scenario. Any thoughts on this? please share your comments.

[self.navController dismissViewControllerAnimated:animated 
                                       completion:^{
                                                      [self doSomething];
                                                  }];

我们应该在这里使用弱自我吗?

Should we use weak self here?

推荐答案

这不是保留周期。保留周期为

This is not a retain cycle. A retain cycle would be

self -> block -> self

在这种情况下,我们有

animation framework -> block
block -> self

其中第一个保留只是临时的 - 当动画结束时块被释放。即使发生保留周期,它也只是暂时的,并且不会阻止对象的重新分配。

where the first retain is only temporary - the block gets released when the animation ends. Even if a retain cycle happens, it will be only temporary and it won't prevent object deallocation.

这篇关于我们是否需要在ARC的UIAnimationBlocks中使用__weak self?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆