2011-01-24 43 views
1

我已經做了打大量的圖片像下面的效果:的UIImage觀看動畫問題

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效果添加到this.One畫面逐漸消失,然後另一張照片逐步顯現。 謝謝

+0

您的for循環看起來怪怪太 – Ben 2011-01-25 06:39:40

回答

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 ]; 
} 
+0

感謝您的建議,我想,已經和它會按預期工作,但如何實現總是重複它。 – 2011-01-25 06:11:54