Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Joseph Rimar
17,101 PointsSlow animation for Crystal Ball app
Has anyone else noticed the delay in the background animation when you first run the crystal ball app. After the first animation runs any subsequent ones are noticeably faster. I suppose this is because when the animation is first called iOS must load all 60 images into memory and they remain cached for later use. I've been trying to 'preload' the images to memory to make everything faster with not so stellar results. The best way I can find to attempt this is to pre draw the images before they are needed, but I can hardly notice any difference in loading time. I've used the following code I found from stackoverflow:
// First Image
-(void) preLoad1: (UIImage *)image {
CGImageRef CB0001 = image.CGImage;
size_t width = CGImageGetWidth(CB0001);
size_t height = CGImageGetHeight(CB0001);
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, width, height, 8, width *4, space, kCGBitmapAlphaInfoMask & kCGImageAlphaPremultipliedFirst);
CGColorSpaceRelease(space);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), CB0001);
CGContextRelease(context);
}
//Second Image
-(void) preLoad2: (UIImage *)image {
CGImageRef CB0002 = image.CGImage;
size_t width = CGImageGetWidth(CB0002);
size_t height = CGImageGetHeight(CB0002);
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, width, height, 8, width *4, space, kCGBitmapAlphaInfoMask & kCGImageAlphaPremultipliedFirst);
CGColorSpaceRelease(space);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), CB0002);
CGContextRelease(context);
}
I created method for each image and put them in a separate file, then called the class in the VIewController.m file. Any ideas how to make it work better???