【发布时间】:2012-03-07 13:15:23
【问题描述】:
我认为将一组动画传递给一个一个接一个地运行所有动画的内部函数是一个绝妙的主意,这样我就不需要在彼此和彼此的完成块中嵌套动画。所以我写了一个小方法来测试它,你猜怎么着,它像地狱一样崩溃。但我不明白为什么。这是我的方法:
+(void) internalAnimateWithArrayOfAnimationBlocks:(NSArray*) animationBlocks withIndex:(NSUInteger) index withCompletionAnimation:(void (^)(BOOL finished)) completionBlock {
__block NSArray* newAnims = animationBlocks;
__block NSUInteger theIndex = index;
if (index < [newAnims count] - 1) {
[UIView animateWithDuration:0.1 animations:^{
void (^animBlock) (void) = [newAnims objectAtIndex:theIndex];
animBlock();
theIndex++;
[RMAnimater internalAnimateWithArrayOfAnimationBlocks:newAnims withIndex:theIndex withCompletionAnimation:completionBlock];
}];
}
else {
[UIView animateWithDuration:0.1 animations:^{
void (^animBlock) (void) = [newAnims objectAtIndex:theIndex];
animBlock();
theIndex++;
} completion:completionBlock];
}
}
+(void) animateWithArrayOfAnimationBlocks:(NSArray*) animationBlocks withCompletionAnimation:(void (^)(BOOL finished)) completionBlock {
[RMAnimater internalAnimateWithArrayOfAnimationBlocks:animationBlocks withIndex:0 withCompletionAnimation:completionBlock];
}
我这样传递这个动画:
NSMutableArray* animations = [NSMutableArray array];
[animations addObject:^{
CGRect frame = theTile.textField.frame;
frame.origin.x -= 10;
theTile.textField.frame = frame;
}];
当我调试它时,它会检查我所有的动画,用它的完成块调用最终动画,然后致命地崩溃。我在这里做错了什么?
【问题讨论】:
-
“致命的崩溃”不是很具体。会发生什么?
标签: iphone ios ipad uiview uiviewanimation