代码之家  ›  专栏  ›  技术社区  ›  Scott Fister

UIAnimation导致XCode在一段时间后崩溃

  •  2
  • Scott Fister  · 技术社区  · 11 年前

    我的应用程序在闲置约5-7分钟后在XCode中崩溃。我确信这与用于加载屏幕的动画有关——我粘贴了下面的代码。

    我试着启用Zombie Objects,看看它是否是对已发布对象的调用,并附上调试窗口崩溃时的屏幕截图。

    顺便说一句,如果我按“恢复”,应用程序将继续正常运行。。

    编辑:这是第一次。我设置的全局断点在线路上停止 [UIView animateWithDuration:0.2... 这是输出代码(这次它崩溃了):

    XYZ(14098,0xac3eaa28) malloc: *** mmap(size=2097152) failed (error code=12)
    *** error: can't allocate region
    *** set a breakpoint in malloc_error_break to debug 2013-02-23 13:19:36.653 XYZ[14098:c07] *** Terminating app due to uncaught exception 'NSMallocException', reason: '*** -[NSObject allocWithZone:]: attempt to allocate object of class 'UIViewAnimationState' failed'
    *** First throw call stack: (0x1cf3012 0x17e8e7e 0x1d7e1a4 0x17fca6b 0x17fca55 0x3acceb 0x3baeec 0x3bb1a7 0x37785 0x3badf6 0x3add66 0x3adf04 0x10fc7d8 0x196d014 0x195d7d5 0x1c99af5 0x1c98f44 0x1c98e1b 0x28f17e3 0x28f1668 0x36fffc 0x28fd 0x2825) libc++abi.dylib: terminate called throwing an exception
    

    - (void)startAnimating
    {   
        _isAnimating = YES;
        float rotationAngle = 360.0 / 3;
        [UIView animateWithDuration:0.5
                              delay:0.0
                            options:UIViewAnimationOptionCurveEaseInOut
                         animations:^
        {
            self.marks.transform = CGAffineTransformRotate(self.marks.transform,
                                                           ((rotationAngle + 10) * (M_PI / 180.0)));
    //        self.marks.transform = CGAffineTransformMakeRotation((rotationAngle + 10) * (M_PI / 180.0));
        }
                         completion:^(BOOL finished)
        {
            [UIView animateWithDuration:0.2
                                  delay:0.0
                                options:UIViewAnimationOptionCurveEaseInOut
                             animations:^
            {
                self.marks.transform = CGAffineTransformRotate(self.marks.transform,
                                                               -10 * (M_PI / 180.0));
    //            self.marks.transform = CGAffineTransformMakeRotation(-10 * (M_PI / 180.0));
            }
                             completion:^(BOOL finished)
            {
                self.marks.transform = CGAffineTransformIdentity;
                [self startAnimating];
            }];
        }];
    }
    

    正常崩溃时的屏幕截图:

    Screenshot with NSZombieObjects disabled

    启用NSZombieObjects时的屏幕截图:

    Screenshot with NSZombieObjects enabled

    1 回复  |  直到 11 年前
        1
  •  1
  •   progrmr    11 年前

    第二个动画的完成块正在递归调用startAnimationing。我认为这就是问题的原因。您应该使用循环,或者创建一个重复的动画。