Do we need to use __weak self inside UIAnimationBlocks in ARC?
我们是否需要在UIAnimation块中使用__weak self,如下所示? 如果我们不指定自我弱,它是否会产生保留周期问题?
1 2 3 4 5 6 7 8 9 10 | [UIView animateWithDuration:animationDuration delay:0 options:UIViewAnimationCurveEaseInOut animations:^{ [self doSomething]; } completion:^(BOOL finished) { if (finished) { [self doSomething]; } }]; |
我也对以下场景感到困惑。 有什么想法吗? 请分享您的意见。
1 2 3 4 | [self.navController dismissViewControllerAnimated:animated completion:^{ [self doSomething]; }]; |
我们应该在这里使用弱者吗?
这不是保留周期。保留周期将是
1 | self -> block -> self |
在这种情况下,我们有
1 2 | animation framework -> block block -> self |
第一个保留只是临时的 - 当动画结束时块被释放。即使发生保留周期,它也只是暂时的,并且不会阻止对象的重新分配。
当保留周期可用时,您需要使用
另一种使用
不,它不会创建保留周期,因为块(闭包)未附加到
有关更多信息,请查看Apple的自动参考计数。