gpt4 book ai didi

ios动画一一

转载 作者:行者123 更新时间:2023-11-28 23:07:01 25 4
gpt4 key购买 nike

我有一些看法,想一一展示。我找不到如何做到这一点。相反,如果我使用以下代码,所有 View 都会立即出现。

NSTimer *timer1 = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showStar2) userInfo:nil repeats:NO];
NSTimer *timer2 = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showStar3) userInfo:nil repeats:NO];
NSTimer *timer3 = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showStar4) userInfo:nil repeats:NO];
NSTimer *timer4 = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showStar5) userInfo:nil repeats:NO];

[timer1 fire];
[timer2 fire];
[timer3 fire];
[timer4 fire];


-(void)showStar2
{

[UIView beginAnimations:@"anim1" context:NULL];
[UIView setAnimationDuration:0.5];
[stars[1] setAlpha:1];
[UIView commitAnimations];
}

除了行之外,所有 showStar 函数都是相同的

[UIView beginAnimations:@"anim1" context:NULL];
[stars[1] setAlpha:1];

有不同的论点。 starsUIImageView 的数组。欢迎提出任何建议。

最佳答案

实际上,您恰好在 2 秒后触发所有计时器。更改不同计时器的时间间隔。

相反,您可以使用将重复触发的单个 NSTimer

在 .h 文件中声明 NSUInteger count;

按如下方式启动一个 NSTimer:

[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showStar:) userInfo:nil repeats:YES];

您的showStar 方法应该如下所示:

-(void)showStar:(NSTimer*)timer
{
if( count > 0 )
{
[stars[count-1] setAlpha:0];
}
[UIView beginAnimations:@"anim1" context:NULL];
[UIView setAnimationDuration:0.5];
[stars[count] setAlpha:1];
[UIView commitAnimations];

count++;

if( count == 4 )
{
[timer invalidate];
count = 0;
}
}

已添加以下代码。

if( count > 0 )
{
[stars[count-1] setAlpha:0];
}

关于ios动画一一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9158816/

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