gpt4 book ai didi

iphone - 无法在 UIImageView 中加载 2 个单独的图像序列

转载 作者:行者123 更新时间:2023-11-28 17:44:50 26 4
gpt4 key购买 nike

我不知道这是否可行,但我需要在 imageView 中加载一个图像序列并让它只播放一次,然后卸载该序列并将第二个图像序列加载到同一个 imageView 控件中。

这是我用来加载和播放第一个序列的代码。

imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"openingSeq0001.jpg"], 
...etc.
[UIImage imageNamed:@"openingSeq0140.jpg"],nil];

imageView.animationDuration = 2;
imageView.animationRepeatCount = 1;
[imageView startAnimating];
[self.view addSubview:imageView];
[super viewDidLoad];

我现在想在第二个序列播放完一次后加载并播放到同一个 imageView 控件中。我已经尝试过 if 语句,甚至是 do while 循环以确保动画至少播放一次并将计数器递减 1 并将值传递给 imageView.animationRepeatCount 以等于 0。

imageView.animationRepeatCount = 0;

我以为我可以弄清楚,但我在某处遗漏了一些东西。我可以让第二组图像运行或第一组图像然后就停止了。我为此使用了一个 do while 循环。

我用这个来让它工作:

SEL methodSelector = @selector(startSeqTwo);
[NSTimer scheduledTimerWithTimeInterval:2.5 target:self selector:methodSelector userInfo:nil repeats:NO];

我在第一个代码块之后使用了选择器来加载第一个序列并调用了方法:

-(void)startSeqTwo;

最佳答案

我还没有这样做,但您可以尝试使用 self performSelectorOnMainThread:(SEL) withObject:(id) waitUntilDone:(BOOL) 函数。

-(void)animateSequence{
[self performSelectorOnMainThread:@selector(animateFirstSequence) withObject:nil waitUnitilDone: YES];
[self performSelectorOnMainThread:@selector(animateSecondSequence) withObject:nil waitUnitilDone: YES];
}

-(void)animateFirstSequence{
imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"openingSeq0001.jpg"],
...etc.
[UIImage imageNamed:@"openingSeq0140.jpg"],nil];

imageView.animationDuration = 2;
imageView.animationRepeatCount = 1;
[imageView startAnimating];
}

-(void)animateSecondSequence{
imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"openingSeq0001.jpg"],
...etc.
[UIImage imageNamed:@"openingSeq0140.jpg"],nil];

imageView.animationDuration = 2;
imageView.animationRepeatCount = 1;
[imageView startAnimating];
}

编辑

您还可以尝试检查 UIImageView 是否仍在播放动画,并等到完成后再播放另一个序列。你会这样做:

-(void)animateSequence{
//First sequence
imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"openingSeq0001.jpg"],
...etc.
[UIImage imageNamed:@"openingSeq0140.jpg"],nil];

imageView.animationDuration = 2;
imageView.animationRepeatCount = 1;
[imageView startAnimating];

while([imageView isAnimating])
//Do nothing

//second sequence
imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"openingSeq0001.jpg"],
...etc.
[UIImage imageNamed:@"openingSeq0140.jpg"],nil];

imageView.animationDuration = 2;
imageView.animationRepeatCount = 1;
[imageView startAnimating];
}

关于iphone - 无法在 UIImageView 中加载 2 个单独的图像序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6588585/

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