Delay in array of images animation
===

I have a big delay in my image view animation.

I am creating navigation based application in iPad3.

In viewDidLoad of my third view controller, i created an image view and add it as sub view.

    self.myImageView = [[UIImageView alloc]initWithFrame:CGRectMake(259, 46, 496, 470)];
    self.myImageView.image = [UIImage imageNamed:@"foo.png"];
    [self.view addSubview:self.myImageView];

and on a button click i want to switch myImageView from one animation to another.

There is two animation array of images and i initialized them in viewDidLoad but it takes some delay in calling  [self.myImageView startAnimating]; for the first time.

On my button click i animate my image view as below:


     self.myImageView.animationImages = self.openAnimationArray;
        [self.myImageView startAnimating];
        self.myImageView.animationRepeatCount = 0;

on next button press i animate same ImageView with another set of images array.

    self.myImageView.animationImages = self.closeAnimationArray;
    [self.myImageView startAnimating];
    self.myImageView.animationRepeatCount = 0;

My first problem was delay while navigate to my third view controller.In order to avoid this delay i initialized  and stored the  closeAnimationArray and openAnimationArray in app Delegate [UIApplication sharedApplication].delegate.

I experience this delay only in first time navigation to third view controller. I think it may be due to caching of images, there is no delay in second time navigation to the third view controller.This may be because UIImage imageNamed function caching the images.
So to avoid the delay in first time navigation, i force loaded the images from the app Delegate itself.
 

     NSArray * openAnimationArray = [NSArray arrayWithObjects:[UIImage imageNamed:@"1.png"],[UIImage imageNamed:@"2.png"],[UIImage imageNamed:@"3.png"],[UIImage imageNamed:@"4.png"],[UIImage imageNamed:@"5.png"], nil];
        for (id object in openAnimationArray) 
        {
            
            [object forceLoad];
    
        } 

Method for force loading is given below :

    - (void) forceLoad
    {
        const CGImageRef cgImage = [self CGImage];  
        
        const int width = CGImageGetWidth(cgImage);
        const int height = CGImageGetHeight(cgImage);
        
        const CGColorSpaceRef colorspace = CGImageGetColorSpace(cgImage);
        const CGContextRef context = CGBitmapContextCreate(
                                                           NULL, 
                                                           width, height, 
                                                           8, width * 4, 
                                                           colorspace, kCGImageAlphaNoneSkipFirst);
        
        CGContextDrawImage(context, CGRectMake(0, 0, width, height), cgImage);
        CGContextRelease(context);
    }

But still there is delay in first time animation.It affects my application performance very badly. How can i solve this problem.
                      


