UIAnimation 块在条件子句上崩溃
这段代码因 EXC_BAD_ACCESS 崩溃(请原谅我的格式,我似乎无法处理这个网页编辑器):
@implementation
BOOL imageZoomed=NO;
-(void)makeAnimation {
[UIView animateWithDuration:1.0f
animations:^{
self.myImageView.alpha=1.0f;
if (imageZoomed) {
self.zoomImageView.alpha=0.0f;
tempZoomImageView.alpha=1.0f;
}
}
completion:^(BOOL finished) {
if (imageZoomed) {
self.zoomImageView.alpha=1.0f;
[tempZoomImageView removeFromSuperview];
}
}
}
如果我注释掉动画中的 if 块:,它就可以工作。 imageZoomed 在动画之前和之后调用都没有问题。 我是否缺少块和条件子句或块和变量的内容?
感谢您的回复,马林巴
this code crashes with EXC_BAD_ACCESS (please forgive me the formatting, I seem to be unable to handle this web editor):
@implementation
BOOL imageZoomed=NO;
-(void)makeAnimation {
[UIView animateWithDuration:1.0f
animations:^{
self.myImageView.alpha=1.0f;
if (imageZoomed) {
self.zoomImageView.alpha=0.0f;
tempZoomImageView.alpha=1.0f;
}
}
completion:^(BOOL finished) {
if (imageZoomed) {
self.zoomImageView.alpha=1.0f;
[tempZoomImageView removeFromSuperview];
}
}
}
If I comment out the if-block in animations:, it works.
imageZoomed is called before and after the animation without problems.
Am I missing something with blocks and conditional clauses, or blocks and variables?
Thanks for any reply, marimba
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从表面上看,我认为这段代码本身没有任何问题。没有什么特殊的 WRT 块和条件子句。 WRT 变量有特殊规则,但是看看这段代码,您可能应该没问题。
您可能有一个被过度释放的对象或类似的东西。我建议仔细查看 self、zoomImageView 和 tempZoomImageView 作为嫌疑人,因为它们位于 if 块中...尝试启用 NSZombiesEnabled 以在向过度释放的对象发送消息时获取异常。
On the surface, I don't see anything wrong with this code per se. There's nothing special WRT blocks and conditional clauses. There ARE special rules WRT variables, but looking at this code, you should probably be fine.
You probably have an object that's being over released or something along those lines. I suggest taking a close look at self, zoomImageView, and tempZoomImageView as suspects, since they're in the if block... Try enabling NSZombiesEnabled to get an exception at the point your over released object is messaged.
不要忘记“];”
don't forget the " ]; "