michael.cheng
michael.cheng

Reputation: 13

UIImage view animation problem

I have done the effect of playing lots of images like below:

NSInteger faceNum = 12;

NSMutableArray *faceArray = [[NSMutableArray alloc] initWithCapacity:faceNum];

for (int i = 1;i<faceNum+1; i++) {
    NSString *facename = [[NSBundle mainBundle] 
      pathForResource:[NSString   stringWithFormat:@"animationFace%d",i] ofType:@"png"];    
    UIImage *faceImage = [UIImage imageWithContentsOfFile:facename];    
    [faceArray addObject:faceImage];
}

 UIImageView *faceView = [[UIImageView alloc] 
   initWithFrame:CGRectMake(414, 157, 161, 124)];

 faceView.animationImages = faceArray;    
 faceView.animationDuration = 30;    
 faceView.animationRepeatCount = 0;

 [faceView startAnimating];    
 [self.view addSubview:faceView];    
 [faceView release];    
 [faceArray release];

And how to add the EaseInEaseOut effect to this.One picture disappear gradually,then another picture appear gradually. Thanks

Upvotes: 1

Views: 317

Answers (1)

Ankit
Ankit

Reputation: 4710

There is no inbuilt fade-in and out feature with imageview startAnimating. You can achieve this by manually setting the alpha of two view laid over each other:

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5f];

    imageviewToFadeOut.alpha = 0.0f;
    imageviewToFadeIn.alpha = 1.0f;

    [UIView commitAnimations];

and setImage manually alternatively to these UIViews.

[imageview setImage:image];

and to recursively call this method, use something like [self performSelector:@selector(methodname) withObject: afterDelay: ] inside the method itself.

Edit: For clarity, specifying the recursion to call this method over and over with delay:

-(void)methodname {

.. (do your task)
[self performSelector:@selector(methodname) withObject:NULL afterDelay:10 ];
}

Upvotes: 2

Related Questions