gpt4 book ai didi

iOS 应用程序在 [UIView animateKeyframesWithDuration :] 期间崩溃

转载 作者:搜寻专家 更新时间:2023-10-30 20:17:59 58 4
gpt4 key购买 nike

我有一个带有关键帧动画的 iOS 应用。最后一个关键帧即将结束时,我的应用程序崩溃并出现此错误:

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

我怀疑这可能是无意中嵌套动画的问题。有人遇到过这样的问题吗?

如果我用普通动画 block 替换关键帧动画,应用程序不会崩溃。

在关键帧动画中,我更改了 ScrollView 的内容偏移量和其他一些内容。我添加了 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

更新:(相关代码)

我单步调试了调试器中的代码。动画 block 完成得很好。一旦我越过线进入完成 block ,就会发生崩溃。

只有当我将开始时间设置为 > 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
}];

最佳答案

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

这是由于您访问数组中的元素超过数组中的项目数而发生的。查看您的代码,我看不到您在哪里使用数组,但请放心,您正在某处使用它(可能是在您忽略发布的代码中)。

由于明显的访问索引:4294967295,您显然正在尝试访问索引 -1 处的元素,但它是无符号的,因此显示为 4294967295。

关于iOS 应用程序在 [UIView animateKeyframesWithDuration :] 期间崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22399434/

58 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com