gpt4 book ai didi

objective-c - 如何在代码完成之前停止执行 FOR 循环

转载 作者:行者123 更新时间:2023-11-28 19:23:47 24 4
gpt4 key购买 nike

我做了这个东西。除了向我自己证明之外,它没有其他目的。本质上,我正在循环移动我在屏幕周围创建的 View 。问题是它不会等到完成一个动画后才开始另一个动画,因此 View 会绕过前两个并在 for 循环完成后在最后一个 toastRect 结束,并且在那之后它不会继续移动。如何强制代码完成每个动画,然后再继续下一个动画?

int i;
for (i=0; i < 100; i++) {

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:9];
toast.view.frame = toastRect1;
[UIView commitAnimations];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:9];
toast.view.frame = toastRect2;
[UIView commitAnimations];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:9];
toast.view.frame = toastRect;
[UIView commitAnimations];
NSLog(@"%d",i);

}

}

最佳答案

我认为您需要使用 + (void)setAnimationDidStopSelector:(SEL)selector。仔细看看http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html如果你愿意的话。

关于objective-c - 如何在代码完成之前停止执行 FOR 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6246236/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com