2012-11-13 38 views
0

我發現這個代碼,這是非常有益的,以避免在第一動畫延遲:UIImage的動畫延遲陣列

NSMutableArray *menuanimationImages = [[NSMutableArray alloc] init]; 

for (int aniCount = 1; aniCount < 21; aniCount++) { 
    NSString *fileLocation = [[NSBundle mainBundle] pathForResource: [NSString stringWithFormat: @"bg%i", aniCount + 1] ofType: @"png"]; 
    // here is the code to pre-render the image 
    UIImage *frameImage = [UIImage imageWithContentsOfFile: fileLocation]; 
    UIGraphicsBeginImageContext(frameImage.size); 
    CGRect rect = CGRectMake(0, 0, frameImage.size.width, frameImage.size.height); 
    [frameImage drawInRect:rect]; 
    UIImage *renderedImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    [menuanimationImages addObject:renderedImage]; 
} 

settingsBackground.animationImages = menuanimationImages; 

但我想有時使用相同的圖像 - 我可以手動填寫我的陣列上面的代碼內經由

testArray = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"test_001.png"], 


          [UIImage imageNamed:@"test_002.png"], 

          [UIImage imageNamed:@"test_001.png"], 
nil]; 

感謝您的想法!

+0

是的,你可以使用同樣的圖像 – Mutawe

回答

0

是的,你可以使用此

UIImageView * animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200,200)]; 

testArray = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"test_001.png"], [UIImage imageNamed:@"test_002.png"],[UIImage imageNamed:@"test_001.png"],nil]; 
animTime =3.0; 
[animatedImageView setAnimationImages:testArray] ; 
animatedImageView.animationDuration = animTime; 
animatedImageView.animationRepeatCount = 1; 
[self.view addSubview: animatedImageView]; 
[animatedImageView startAnimating]; 
+0

是 - 但對我來說它預裝我的圖片是很重要的 - 所以會有在第一個動畫沒有延遲... – user1719539

+0

你可以推遲你的意見來處理你的意思,例如: – Mutawe

+0

通過睡眠? – user1719539