gpt4 book ai didi

cocoa - 如何在 10 秒内循环播放动画

转载 作者:行者123 更新时间:2023-12-03 17:21:57 25 4
gpt4 key购买 nike

LogoAnimation.animationImages= [NSArray arrayWithObjects:如何在循环动画之间实现 10 秒暂停“中断”?就像第一个动画一样,运行 10 次暂停,10 秒后,相同的动画一次又一次地运行。我尝试了一切,但我不知道如何解决它!这是我的代码:

ViewController.m

- (void)viewDidLoad
{
[super viewDidLoad];

LogoAnimation.animationImages= [NSArray arrayWithObjects:

[UIImage imageNamed:@"TestAnimation_01"],
[UIImage imageNamed:@"TestAnimation_02"],
[UIImage imageNamed:@"TestAnimation_03"],
[UIImage imageNamed:@"TestAnimation_04"],
[UIImage imageNamed:@"TestAnimation_05"],
[UIImage imageNamed:@"TestAnimation_06"], nil];


[LogoAnimation setAnimationRepeatCount:1];
LogoAnimation.animationDuration = 2;

[LogoAnimation startAnimating];

[self.view addSubview:LogoAnimation];


}

最佳答案

我可以假设您使用的是 UIImageView 并且 LogoAnimation 和 TestAnimation 实际上应该是同一件事吗?

UIImageView 不提供此功能。要使用 UIImageView 执行此操作,您可以将更多图像添加到数组末尾以对应于同一图像的 10 秒。或者,您可以在 UIImageView 上设置 1 次重复计数,并每 10 秒触发一次 NSTimer 来启动动画。

- (void)viewDidLoad
{
TestAnimation.animationImages= [NSArray arrayWithObjects:

[UIImage imageNamed:@"TestAnimation_01"],
[UIImage imageNamed:@"TestAnimation_02"],
[UIImage imageNamed:@"TestAnimation_03"],
[UIImage imageNamed:@"TestAnimation_04"],
[UIImage imageNamed:@"TestAnimation_05"],
[UIImage imageNamed:@"TestAnimation_06"], nil];


[TestAnimation setAnimationRepeatCount:1];
TestAnimation.animationDuration = 2;
[TestAnimation startAnimating];
[self.view addSubview:TestAnimation];

// You need to add a property to your interface @property (strong) NSTimer *timer;
self.timer = [NSTimer scheduledTimerWithTimeInterval:12.0 target:TestAnimation selector:@selector(startAnimating) userInfo:nil repeats:YES]; // 12.0 interval = 2s animation + 10s wait between.
}

- (void)dealloc {
[self.timer invalidate];
}

关于cocoa - 如何在 10 秒内循环播放动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21981691/

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