简体   繁体   English

块动画 - 如何循环 UIImage 数组

[英]Block animations - how to cycle an array of UIImage

I'm going the direction of block animations, having tried to implement multiple animations and an "on finish" event with UIImageView animations but failing.我正朝着块动画的方向发展,尝试使用 UIImageView 动画实现多个动画和“完成”事件,但失败了。

I have a UIImage array, which I need to cycle backwards through, displaying as I go.我有一个 UIImage 阵列,我需要向后循环,显示为 go。 Here is what I have so far:这是我到目前为止所拥有的:

__block int i = 9;
[UIView animateWithDuration:4.0
                 animations:^{
                     self.fooView.image = fooImage[i];
                     [self.view addSubview:self.fooView];
                     i--;
                }
                 completion:NULL];

This does happily display the 9th element of fooImage[], but it doesn't iterate through the rest.这确实很好地显示了 fooImage[] 的第 9 个元素,但它不会遍历 rest。

Is this a misunderstanding about what blocks can actually do in this context?这是对块在这种情况下实际上可以做什么的误解吗? I tried to also wrap a while loop, decrementing "i", but I ended up with the first element only (I sort of expected that).我还尝试包装一个while循环,递减“i”,但我最终只得到了第一个元素(我有点预料到)。 How should one iterate through an array in this instance - perhaps have 9 different animation blocks?在这种情况下应该如何遍历一个数组 - 可能有 9 个不同的 animation 块?

Any tips will be gratefully received, and thanks for your time任何提示将不胜感激,并感谢您的时间

sc. sc。

Your animations completion handler is NULL, which means nothing is happened after animation is completed.您的动画完成处理程序是 NULL,这意味着在 animation 完成后什么都没有发生。 And it's strange to use animations block if you actually animate nothing.如果您实际上什么都不做动画,那么使用动画块很奇怪。 Animations won't wait 4 seconds before calling competition handler if there is nothing to animate.如果没有任何动画,动画不会在调用比赛处理程序之前等待 4 秒。

__block int i = 9;
void(^process)(void(^recursive)());
process = ^(void(^recursive)()) {
    --i;
    [UIView animateWithDuration:4.0
                     animations:^{
                         NSLog(@"%d", i);
                     }
                     completion:^(BOOL finished) {
                         recursive(recursive);
                     }];
};
process(process);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM