对 UIView 数组进行动画处理

发布于 2024-12-08 17:16:25 字数 312 浏览 0 评论 0原文

我有一组 UIView,我使用以下代码对其进行动画处理:

for (int i = 0; i<(int)viewArray.count; i++) {
    UIView *view = [viewArray objectAtIndex:i];
    CALayer *layer = view.layer;

    //animate the layer

}

我的问题是,是否有任何方法可以在每个动画之间有延迟,例如,它对数组中的一个 UIView 进行动画处理,下一个动画在 0.2 之后开始几秒钟左右?任何帮助将不胜感激!

I have an array of UIViews which I animate with the following code:

for (int i = 0; i<(int)viewArray.count; i++) {
    UIView *view = [viewArray objectAtIndex:i];
    CALayer *layer = view.layer;

    //animate the layer

}

My question is, is there any way to have a delay between every animation, so that, for example, it animates one UIView in the array and the next animation starts after 0.2 seconds or so? Any help would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄意 2024-12-15 17:16:25

您可能想尝试以下方法

float timeDelay = 0.2
float duration = YOUR_DURATION
for (int i = 0; i<(int)viewArray.count; i++) {
    UIView *view = [viewArray objectAtIndex:i];

    //animate the layer
    [UIView animateWithDuration:duration delay:(i+1)*timeDelay
            options: {Check UIView Class Reference on developer.apple.com}
            animations:^{
                   [view.layer fantastic animation here];
            } completion^(BOOL finised){
                   if(finished){
                     //Leave blank if nothing, good practice to implement debuging here or post  animation processes here (like removing a subview from a super)
                   }
            }];

}

请记住,如果您将程序发送到背景,它可能会破坏您的动画,因此请确保您在应用程序委托中回忆起此方法:

- (void)applicationWillEnterForeground:(UIApplication *)application;

希望它有帮助

You may want to try the following

float timeDelay = 0.2
float duration = YOUR_DURATION
for (int i = 0; i<(int)viewArray.count; i++) {
    UIView *view = [viewArray objectAtIndex:i];

    //animate the layer
    [UIView animateWithDuration:duration delay:(i+1)*timeDelay
            options: {Check UIView Class Reference on developer.apple.com}
            animations:^{
                   [view.layer fantastic animation here];
            } completion^(BOOL finised){
                   if(finished){
                     //Leave blank if nothing, good practice to implement debuging here or post  animation processes here (like removing a subview from a super)
                   }
            }];

}

Keep in mind that if u send your program the the background it may break your animations so make sure u recall this method in ur app Delegates:

- (void)applicationWillEnterForeground:(UIApplication *)application;

Hope it helps

寂寞清仓 2024-12-15 17:16:25

使用这个家伙:

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

使用第二个参数。在循环中,调用该函数,将每个递增的数字传递给该参数。

Use this guy:

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

use the second parameter. Inside your loop, call that function, passing an every-increasing number to that parameter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文