UIAnimation 块在条件子句上崩溃

发布于 2024-10-31 18:16:43 字数 720 浏览 0 评论 0原文

这段代码因 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难以启齿的温柔 2024-11-07 18:16:43

从表面上看,我认为这段代码本身没有任何问题。没有什么特殊的 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.

べ繥欢鉨o。 2024-11-07 18:16:43
[UIView animateWithDuration:1.0f
                     animations:^{

                     }
                     completion:^(BOOL finished) {
                         if (finished) {
                         }
                     }];

不要忘记“];”

[UIView animateWithDuration:1.0f
                     animations:^{

                     }
                     completion:^(BOOL finished) {
                         if (finished) {
                         }
                     }];

don't forget the " ]; "

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文