我發現這個代碼,這是非常有益的,以避免在第一動畫延遲: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];
感謝您的想法!
是的,你可以使用同樣的圖像 – Mutawe