开发者

Trouble loading 2 separate image sequences in the UIImageView

开发者 https://www.devze.com 2023-03-18 09:32 出处:网络
I don\'t know if this is possible, but I need to load one image sequence in the imageView and have it play only once, then unload that sequence and load the second image sequence into the same imageVi

I don't know if this is possible, but I need to load one image sequence in the imageView and have it play only once, then unload that sequence and load the second image sequence into the same imageView control.

Here is the code I'm using for loading and playing the first sequence.

imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"开发者_如何学GoopeningSeq0001.jpg"], 
...etc.
[UIImage imageNamed:@"openingSeq0140.jpg"],nil];

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

I now want to load and play the second sequence into the same imageView control once it has played through once. I have tried if statements, even a do while loop to make sure that the animation was at least played once and decremented the counter 1 and passed the value to the imageView.animationRepeatCount to equal 0.

imageView.animationRepeatCount = 0;

I thought I could figure it out, but I'm missing something somewhere. I can get the second grouping of images to run or the first and then is just stops. I used a do while loop for that.

I used this to make it work:

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

I used the selector after the first block of code to load the first sequence and called method:

-(void)startSeqTwo;


I have not done it but you could try using self performSelectorOnMainThread:(SEL) withObject:(id) waitUntilDone:(BOOL) function.

-(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];
}

Edit

You can also try checking if the UIImageView is stil animating and wait until finished to play another sequence. You would do it like this:

-(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];
}


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

This worked.

I used the selector after the first block of code to load the first sequence and called method: -(void)startSeqTwo;

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号