UIImage查看动画问题

时间:2011-01-24 09:26:07

标签: iphone

我已经完成了播放大量图片的效果:

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

如何将EaseInEaseOut效果添加到此。一张图片逐渐消失,然后逐渐出现另一张图片。 感谢

1 个答案:

答案 0 :(得分:2)

imageview startAnimating没有内置的淡入和淡出功能。您可以通过手动设置彼此叠加的两个视图的alpha来实现此目的:

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

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

    [UIView commitAnimations];

和setImage手动交替使用这些UIViews。

[imageview setImage:image];

并以递归方式调用此方法,在方法本身中使用类似[self performSelector:@selector(methodname) withObject: afterDelay: ]的内容。

编辑:为清楚起见,指定递归以反复调用此方法:

-(void)methodname {

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