Here is what I'm trying to do: I want to have an app that displays a full-screen image and have that image animate by sliding a UISlider. A changing slider value will sequence through images of an array creating an animation. This animation is a single character on a turn-table. The character looks as though he is rotating around the turn table as the slider changes value.
This project is a portfolio piece for a 3D artist. The artist gave me a sequence of 180 images of the character rendered at the full screen retina resolution. He also gave be an additional 180 images rendered at the non-retina full screen resolution. The idea is that when somebody is viewing his character from any angle on a retina iPad, they can toggle using a UISwitch between retina and non-retina display. The code posted below works fine on the simulator.
However when running this code on an iPad 4, it works for a bit, then I get a memory warning. Then it crashes. I'm assuming having that many images of that size being displayed as fast as somebody wants to move a slider is too much for the iPad 4 to handle.
I'm curious what limitations I should take into account when working with images like this. Is 180 images way too many? What is a reasonable amount? Is there a more efficient way of producing my desired result? Instead of resorting the guess-and-check method of how many images would not cause it to crash, I figured somebody might have some useful insight on my issue.
@implementation RBViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_imageDisplay.image = [UIImage imageNamed:@"HyperReal_0.png"];
_arrayRetina = [[NSMutableArray alloc] initWithCapacity:180];
_arrayNormal = [[NSMutableArray alloc] initWithCapacity:180];
for(int i = 0; i < 179; i++)
{
NSString *myImageString = [[NSString alloc] initWithFormat:@"HyperReal_%i.png", i];
UIImage *myImageGraphic = [UIImage imageNamed:myImageString];
[_arrayRetina addObject:myImageGraphic];
}
for(int i = 0; i < 179; i++)
{
NSString *myImageString = [[NSString alloc] initWithFormat:@"lameHyperReal_%i.png", i];
UIImage *myImageGraphic = [UIImage imageNamed:myImageString];
[_arrayNormal addObject:myImageGraphic];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)switchButton:(id)sender {
if (_switchOnForRetina.isOn == YES)
{
_imageDisplay.image = [_arrayRetina objectAtIndex:_sliderBar.value];
}
else
_imageDisplay.image = [_arrayNormal objectAtIndex:_sliderBar.value];
}
- (IBAction)changeSlider:(id)sender {
if (_switchOnForRetina.isOn == YES)
{
_imageDisplay.image = [_arrayRetina objectAtIndex:_sliderBar.value];
}
else
_imageDisplay.image = [_arrayNormal objectAtIndex:_sliderBar.value];
}
@end