我有以下动画块:
[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);
}];
}];
基本上它是一个视图控制器的字典,它是我想要动画的视图,但奇怪的是它只执行一个动画。不是全部。为什么是这样?是否可以在动画块中进行枚举?
答案 0 :(得分:0)
枚举您的观点并在枚举中制作动画
[self.visibleViewControllers_ enumerateKeysAndObjectsUsingBlock:^
[UIView animation.....
你做了一个动画并枚举了这个动画中的所有视图。只是转过来
答案 1 :(得分: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");
}];
}