我发现这段代码对于避免第一次动画延迟非常有帮助:
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];
感谢您的想法!