OS X 10.6中使用的NSViewAnimations在OS X 10.9中停止工作,后续动画未触发

时间:2014-03-11 01:07:48

标签: macos osx-snow-leopard osx-mavericks nsviewanimation

我在OS X 10.6中编写了一些动画代码,但是当我为10.9重新编译应用程序时,动画无法正常工作。

我有一系列按钮,对于每个按钮,我的目标是让它缩小,然后恢复到正常尺寸,然后缩小,然后恢复到正常尺寸(“弯曲”几次)。

NSMutableArray *animations = [NSMutableArray arrayWithCapacity:buttons.count];

NSMutableArray *allAnimations = [NSMutableArray arrayWithCapacity:buttons.count*4];

for(NSButton *button in buttons) {
    // store the original frame and generate the smaller frame
    NSRect originalFrame = button.frame;
    NSRect smallFrame = [self smallRectForRect:originalFrame scale:0.9];

    // build dictionaries which describe the animations from normal-to-small and vice versa
    NSMutableDictionary *normalToSmall = [NSMutableDictionary dictionary];
    [normalToSmall setObject:button forKey:NSViewAnimationTargetKey];
    [normalToSmall setObject:[NSValue valueWithRect:originalFrame] forKey:NSViewAnimationStartFrameKey];
    [normalToSmall setObject:[NSValue valueWithRect:smallFrame] forKey:NSViewAnimationEndFrameKey];

    NSMutableDictionary *smallToNormal = [NSMutableDictionary dictionary];
    [smallToNormal setObject:button forKey:NSViewAnimationTargetKey];
    [smallToNormal setObject:[NSValue valueWithRect:smallFrame] forKey:NSViewAnimationStartFrameKey];
    [smallToNormal setObject:[NSValue valueWithRect:originalFrame] forKey:NSViewAnimationEndFrameKey];

    // create, and chain together, the shrink, reset, shrink, reset animation chain
    NSViewAnimation *animation1 = [self createAnimationWithDictionary:normalToSmall duration:duration startingAfterAnimation:nil];
    NSViewAnimation *animation2 = [self createAnimationWithDictionary:smallToNormal duration:duration startingAfterAnimation:animation1];
    NSViewAnimation *animation3 = [self createAnimationWithDictionary:normalToSmall duration:duration startingAfterAnimation:animation2];
    NSViewAnimation *animation4 = [self createAnimationWithDictionary:smallToNormal duration:duration startingAfterAnimation:animation3];

    // store all of the animations in an array just in case ARC wants to release them prematurely.
    [allAnimations addObjectsFromArray:@[animation1, animation2, animation3, animation4]];

    // Store the first animation, so that we can start each of the chains after we're done creating them.
    [animations addObject:animation1];
}

// start the first animation in each chain
for (NSViewAnimation *animation in animations) {    
    [animation startAnimation];
}

以下是我用于创建每个动画的函数:

- (NSViewAnimation*) createAnimationWithDictionary:(NSDictionary*)animationDictionary duration:(float)duration startingAfterAnimation:(NSViewAnimation*)previousAnimation {
    NSViewAnimation *animation = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:animationDictionary]];
    [animation setDuration:duration];
    [animation setDelegate:self];

    if (previousAnimation != nil) {
        [animation startWhenAnimation:previousAnimation reachesProgress:1.0];
    }
    return animation;
}

我将我的窗口控制器设置为委托,这样我就能看到动画的开始和结束,看起来只有每个链中的第一个动画开始和结束。配置为-startWhenAnimation:reachesProgress:1.0的后续动画似乎根本没有开始。

为什么后续动画不会开始运行?

0 个答案:

没有答案