2014-03-14 67 views
3

崩溃我有一个关键帧动画的iOS应用程序。一旦最后一个关键帧即将结束,我的应用程序崩溃,与此错误:iOS应用程序在[UIView animateKeyframesWithDuration:]

*** Terminating app due to uncaught exception 'NSRangeException', 
reason: '*** -[__NSArrayM objectAtIndex:]: index 4294967295 beyond 
bounds for empty array' 

我有怀疑,也许这是无意中嵌套动画的问题。有没有人遇到这样的问题?

如果我用正常的动画块替换关键帧动画,应用程序不会崩溃。

在关键帧动画中,我更改了滚动视图的内容偏移和其他一些内容。我添加了objc消息日志记录,但即使这样也没有给出为什么发生这种情况的线索。

完整堆栈跟踪:

*** First throw call stack: 
(
    0 CoreFoundation      0x021b15e4 __exceptionPreprocess + 180 
    1 libobjc.A.dylib      0x01b968b6 objc_exception_throw + 44 
    2 CoreFoundation      0x021524e6 -[__NSArrayM objectAtIndex:] + 246 
    3 UIKit        0x0095288d __35-[UIViewKeyframeAnimationState pop]_block_invoke_3 + 415 
    4 CoreFoundation      0x0222e446 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 102 
    5 CoreFoundation      0x0222e352 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 290 
    6 CoreFoundation      0x021ab0a5 -[NSArray enumerateObjectsUsingBlock:] + 53 
    7 UIKit        0x009524e7 __35-[UIViewKeyframeAnimationState pop]_block_invoke + 518 
    8 CoreFoundation      0x0223b13a __65-[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke + 106 
    9 CoreFoundation      0x0223b03e -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 190 
    10 CoreFoundation      0x0219f525 -[NSDictionary enumerateKeysAndObjectsUsingBlock:] + 53 
    11 UIKit        0x00952268 -[UIViewKeyframeAnimationState pop] + 385 
    12 UIKit        0x0094f336 +[UIViewAnimationState popAnimationState] + 47 
    13 UIKit        0x0096729a +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 508 
    14 UIKit        0x009688b9 +[UIView(UIViewKeyframeAnimations) animateKeyframesWithDuration:delay:options:animations:completion:] + 163 

更新:(相关代码)

我通过调试代码加强。动画块完成正常。只要我跨过这条线进入完成块,就会发生崩溃。

当我设置的开始时间到> 0

所讨论的阵列似乎是动画栈的一部分,我自己的阵列而不是一个(均未我的动画代码期间被访问)它只崩溃。

有没有办法转储UIView动画状态?

[UIView animateKeyframesWithDuration:1.0 delay:0.0 options:0 animations:^{ 

     [UIView addKeyframeWithRelativeStartTime:0.1 relativeDuration:0.9 animations:^{ 

      snapshot.center = snapshotAwayCenter; 
      snapshot.transform = rotateOutTransform; 

      CGFloat pageOffset = ...// calculate page offset 
      self.scrollView.contentOffset = CGPointMake(pageOffset, 0.0); 

      // block returns (stepped through in debugger) 
     }]; 

    } completion:^(BOOL finished){ // When stepping over this line, the crash happens 
     // more stuff here 
}]; 
+1

发表您的相关代码 – codercat

+0

,会出现[__NSArrayM objectAtIndex:]这当您尝试获取该索引处不存在的索引处的对象时,会出现错误。你应该检查你的数组 –

+1

你能够发布你的代码,调用堆栈没有任何用处。 4294967295看起来有点高吗?那看起来像一个对象引用 – Flexicoder

回答

2

崩溃不是由于UIView的addKeyframeWithRelativeStartTime:方法造成的。

这是因为您访问的数组中的元素超出了数组中的元素数量。看看你的代码,我看不到你在使用数组的位置,但请放心,你正在做某处(可能在你忘记发布的代码中)。

由于表观访问的索引:4294967295你显然尝试索引来访问元素-1,但它是无符号的,并且4294967295

相关问题