2

我有以下动画块:

[UIView animateWithDuration:3.0 animations:^{
            NSLog(@"INDEX %d",  index);

            [self.visibleViewControllers_ enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {                                 
                UIViewController *viewController = (UIViewController *)obj;
                if (viewController.view.tag != index){
                    if (viewController.view.tag < index){
                        NSLog(@"LOWER VIEW WITH TAG %d", viewController.view.tag);
                        [viewController.view setFrameY:self.contentOffset.y - viewController.view.frameHeight];
                    } else if (viewController.view.tag > index){
                        NSLog(@"UPPER VIEW WITH TAG %d", viewController.view.tag);
                        [viewController.view setFrameY:600];
                    } else {
                        [viewController.view setFrame:CGRectMake(0, self.contentOffset.y, selectedView.frameWidth, 460)];
                    }
                }
            }];
            //[selectedView setFrame:CGRectMake(0, self.contentOffset.y, selectedView.frameWidth, 460)];
        }completion:^(BOOL finished){
            [self.visibleViewControllers_ enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {                                 
                UIViewController *viewController = (UIViewController *)obj;
                NSLog(@"VIEW CONTROLLER Y IS %f AT INDEX %d", viewController.view.frameY, viewController.view.tag);
            }];

        }];

基本上它是一个视图控制器字典,它是我想要动画的视图,但奇怪的是它只执行一个动画。不是全部。为什么是这样?是否可以在动画块内进行枚举?

4

2 回答 2

0

枚举您的视图并在您的枚举中为它们设置动画

[self.visibleViewControllers_ enumerateKeysAndObjectsUsingBlock:^
    [UIView animation.....

你做了一个动画并枚举了这个动画中的所有视图。把它转过来

于 2012-06-06T14:53:26.687 回答
0

你有没有尝试过这样的事情:

- (void) startAnimationLoop {
    keyIndex = 0;
    keysToLoopThrough = [self.visibleViewControllers_ allKeys];
    [self animate];
}

- (void) animate {
    UIViewController *viewController = [self.visibleViewControllers_ objectForKey:[keysToLoopThrough objectAtIndex:keyIndex]];
    [UIView animateWithDuration:3.0 animations:^{
            if (viewController.view.tag != index){
                if (viewController.view.tag < index){
                    NSLog(@"LOWER VIEW WITH TAG %d", viewController.view.tag);
                    [viewController.view setFrameY:self.contentOffset.y - viewController.view.frameHeight];
                } else if (viewController.view.tag > index){
                    NSLog(@"UPPER VIEW WITH TAG %d", viewController.view.tag);
                    [viewController.view setFrameY:600];
                } else {
                    [viewController.view setFrame:CGRectMake(0, self.contentOffset.y, selectedView.frameWidth, 460)];
                }
             }
        }completion:^(BOOL finished){
            keyIndex++;
            if (keyIndex < [keysToLoopThrough count])
                [self animate];
            else NSLog("Finished");
        }];
}
于 2012-06-06T15:59:48.367 回答