【发布时间】:2011-08-15 14:29:07
【问题描述】:
请看下面的代码。用图片显示动画效果。
UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; // ref count = 1
int offX = imgView.frame.size.width / 6;
int offY = (imgView.frame.size.height - 44) / 6;
imgView.frame = CGRectMake(offX, offY, imgView.frame.size.width - offX * 2,
(imgView.frame.size.height - 44) - offY * 2);
[overlayView addSubview:imgView]; // ref count = 2
[imgView release]; // ref count = 1
[UIView animateWithDuration:1.0 animations:^{
[imgView setCenter:CGPointMake(TRASH_X, TRASH_Y)];
[imgView setTransform:CGAffineTransformMakeScale(0.1, 0.1)];
[imgView setAlpha:0.5];
} completion:^(BOOL finished) {
[imgView removeFromSuperview]; // ref count = 0? destroy imgView object?
}];
从上面的代码中,如果我删除 [imgView release] 没有崩溃。但是,上面的代码使完成例程崩溃。为什么?我认为引用计数的变化就像评论一样。那么应该不会崩溃。
您能解释一下为什么完成例程会崩溃吗?
【问题讨论】:
标签: iphone animation crash block