TKCalendar - Custom image for day? - ios

I'm using the standard implementation of the TKCalendar for iOS and because there isn't much documentation on it I was wondering if anyone knows of a simply way of setting a custom image for a day of the month.
Any help is greatly appreciated!

You may follow below steps to set custom image
You have to right click the TapkuLibrary.bundle and select show packet content
Now you can see folder as Images if you open that image folder you can see some folders
Among that folders you have to open the calendar folder
You can see so many images. now you can change images whatever you want
I think it may help you.

Just edit the images in TapkuLibrary.bundle (right click, show packet content)

No, that's all of your answers are wrong. What I wanted was the ability to change each day's image to a custom image that I would choose for every day.
I hacked the code together and got it to work . If anyone is looking for how to do this, just got go to TKCalendarMonthView.m and find the
- (void) drawRect:(CGRect)rect
method. Now in this method, copy in the following (this is a simplified version of the code that I have so you have to build it up yourself):
CGContextRef context = UIGraphicsGetCurrentContext();
UIImage *tile = [UIImage imageWithContentsOfFile:TKBUNDLE(#"TapkuLibrary.bundle/Images/calendar/Month Calendar Date Tile.png")];
CGRect r = CGRectMake(0, 0, 46, 44);
CGContextDrawTiledImage(context, r, tile.CGImage);
int index = 0;
UIFont *font = [UIFont boldSystemFontOfSize:dateFontSize];
UIFont *font2 =[UIFont boldSystemFontOfSize:dotFontSize];
UIColor *color = [UIColor grayColor];
//first do the boxes that are still visible from the previous month
//
//
if(firstOfPrev>0){
[color set];
for(int i = firstOfPrev;i<= lastOfPrev;i++){
r = [self rectForCellAtIndex:index];
///////////////////////////
///////////////////////////
///////////////////////////
int indexMoved = 7;
r.origin.y -= indexMoved; //this moves the block to put it back in it's place
//add an image to the rect - note you can add them over each other
[[UIImage imageNamed:[NSString stringWithFormat:#"t.png"]] drawInRect:r];
r.origin.y += indexMoved; //move back the block
///////////////////////////
///////////////////////////
///////////////////////////
if ([marks count] > 0)
[self drawTileInRect:r day:i mark:[[marks objectAtIndex:index] boolValue] font:font font2:font2];
else
[self drawTileInRect:r day:i mark:NO font:font font2:font2];
index++;
}
}
//Now to blocks for current month
//
//
color = [UIColor colorWithRed:59/255. green:73/255. blue:88/255. alpha:1];
[color set];
for(int i=1; i <= daysInMonth; i++){
r = [self rectForCellAtIndex:index];
///////////////////////////
///////////////////////////
///////////////////////////
int indexMoved = 7;
r.origin.y -= indexMoved; //this moves the block to put it back in it's place
//add an image to the rect - note you can add them over each other
[[UIImage imageNamed:[NSString stringWithFormat:#"t.png"]] drawInRect:r];
r.origin.y += indexMoved; //move back the block
///////////////////////////
///////////////////////////
///////////////////////////
if(today == i){ //this is done to highlight today's block
int indexMoved = 7;
r.origin.y -= indexMoved;
[[UIColor colorWithRed:59/255. green:73/255. blue:88/255. alpha:1] set];
//set the image to whatever you want today's block to have
[[UIImage imageNamed:[NSString stringWithFormat:#"Tile-Border-Green.png"]] drawInRect:r];
r.origin.y += indexMoved;
}
if ([marks count] > 0)
[self drawTileInRect:r day:i mark:[[marks objectAtIndex:index] boolValue] font:font font2:font2];
else
[self drawTileInRect:r day:i mark:NO font:font font2:font2];
index++;
}
//Finally, do blocks for the next month who's blocks are visible
//
//
[[UIColor grayColor] set];
int i = 1;
while(index % 7 != 0){
r = [self rectForCellAtIndex:index] ;
///////////////////////////
///////////////////////////
///////////////////////////
int indexMoved = 7;
r.origin.y -= indexMoved; //this moves the block to put it back in it's place
//add an image to the rect - note you can add them over each other
[[UIImage imageNamed:[NSString stringWithFormat:#"t.png"]] drawInRect:r];
r.origin.y += indexMoved; //move back the block
///////////////////////////
///////////////////////////
///////////////////////////
if ([marks count] > 0)
[self drawTileInRect:r day:i mark:[[marks objectAtIndex:index] boolValue] font:font font2:font2];
else
[self drawTileInRect:r day:i mark:NO font:font font2:font2];
i++;
index++;
}
Notice that it's spilt into three main areas (each with a for loop). These are (in order) the blocks from the previous month that are still visible, the blocks from the current month and lastly the blocks from the coming month that are visible in the current view.
I really hope this helps someone because it took be a lot of headache to set up!
Cheers!

Related

How to animate by changing the background image and chnage the position of an UIImageView

I am interested in obtaining an animation that not only animates from point A to point B but also changes the background image.
Say the initial position is 0,0 and the finis one is 0,100 ; the duration is 1 second, and i have 4 images for the background, then i want the background to change every 0/4 seconds and 25 px.
Until now I have the next code that animates the images but i still need to implement the movement and I don't know how to do just that.
Thanks in advance and here is what code I have until now:
UIImageView * animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50,50)];
testArray = [[NSArray alloc] initWithObjects:[UIImage imageNamed:#"test_1.png"], [UIImage imageNamed:#"test_2.png"], [UIImage imageNamed:#"test_3.png"],nil];
animTime =3.0;
[animatedImageView setAnimationImages:testArray] ;
animatedImageView.animationDuration = animTime;
animatedImageView.animationRepeatCount = 1;
[self.view addSubview: animatedImageView];
[animatedImageView startAnimating];
UPDATE:
I have implemented the answer of Mobile Project Lab into my code
// I have a pathArray that is in C style and is bidimensional, that stores the path in reverse
// the maps is a 2d tile map
// the dimensions of the tiles are 64x64 px
//thes size of the character is 128x128
for (int possitionInThePathArray = sizeOfPathArray - 1; possitionInThePathArray >= 0; possitionInThePathArray--) {
xWalkingDirection = pathArray[possitionInThePathArray-1][1] - pathArray[possitionInThePathArray][1];
yWalkingDirection = pathArray[possitionInThePathArray-1][0] - pathArray[possitionInThePathArray][0];
if (xWalkingDirection== 0 && yWalkingDirection == -1){
//walking animation to North for 1 tile
NSArray *testArray;
float animTime;
testArray = [[NSArray alloc] initWithObjects:[UIImage imageNamed:#"scientist_s0.png"],
[UIImage imageNamed:#"scientist_s1.png"],
[UIImage imageNamed:#"scientist_s2.png"],
[UIImage imageNamed:#"scientist_s3.png"],
[UIImage imageNamed:#"scientist_s4.png"],
[UIImage imageNamed:#"scientist_s5.png"],
[UIImage imageNamed:#"scientist_s6.png"],
[UIImage imageNamed:#"scientist_s7.png"],
[UIImage imageNamed:#"scientist_s8.png"],
[UIImage imageNamed:#"scientist_s9.png"], nil]; // 4th image added
animTime = 10.0; // time is changed to 10.0
[myCharacterFrame setAnimationImages:testArray];
myCharacterFrame.animationDuration = animTime;
myCharacterFrame.animationRepeatCount = 1;
[myCharacterFrame startAnimating];
[UIView animateWithDuration:animTime
animations:^{
myCharacterFrame.frame = CGRectOffset(myCharacterFrame.frame, 0.0f, -64.0f); // move 100 on x axis, 0 on y axis
}
completion:^(BOOL finished){
NSLog(#"animation done");
}];
yMyCharacterFrame = yMyCharacterFrame-64.0;
myCharacterFrame.frame = CGRectMake(xMyCharacterFrame, yMyCharacterFrame, 128, 128);
myCharacterFrame.image = [UIImage imageNamed:#"scientist_s0.png"];
}else if (xWalkingDirection== 1 && yWalkingDirection == 0){
//walking animation to Est for 1 tile
.....
//and so on for all the four directions of walking
The issue that I am facing now is that the animation are not triggered correctly, so that one animation takes places before the code moves on
NSArray *testArray;
float animTime;
UIImageView *animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
testArray = [[NSArray alloc] initWithObjects:[UIImage imageNamed:#"test_001.png"], [UIImage imageNamed:#"test_002.png"],[UIImage imageNamed:#"test_001.png"], [UIImage imageNamed:#"test_002.png"], nil]; // 4th image added
animTime = 1.0; // time is changed to 1.0
[animatedImageView setAnimationImages:testArray];
animatedImageView.animationDuration = animTime;
animatedImageView.animationRepeatCount = 1;
[self.view addSubview: animatedImageView];
[animatedImageView startAnimating];
[UIView animateWithDuration:animTime
animations:^{
animatedImageView.frame = CGRectOffset(animatedImageView.frame, 100.0f, 0.0f); // move 100 on x axis, 0 on y axis
}
completion:^(BOOL finished){
NSLog(#"animation done");
}];

Drawing 2 UIImage merged with different UILabel

I've been trying to create a for loop which take UILabel.text and merge it into an UIImage then save it into an instance and then when getting into the for loop second time it would save the result in different instance.
The problem that I'm facing is that it is saving the first UIImage but with low quality and skipping the second one. I've even tried to do the UIImage saving code in a button action but still didn't work.
-(void)CreateTheImage{
UIImage * img = [UIImage imageNamed:#"SquareBackground.jpg"];
UIGraphicsBeginImageContext(_imgView.bounds.size);
int Counter = 0;
for (UIView * view in [_imgView subviews]){
[view removeFromSuperview];
}
NSString *txt1 = #"Test";
NSString *txt2 = #"Worked Well";
[array addObject:txt1];
[array addObject:txt2];
UILabel *lbl = [[UILabel alloc]init];
NSLog(#"%i",[array count]);
NSLog(#"Before the loop");
for (int x = 0; x < [array count]; x++) {
NSLog(#"Entered the loop");
NSLog(#"x = %i",x);
lbl.text = [array objectAtIndex:x];
NSLog(#"lbl.text = %#",[array objectAtIndex:x]);
lbl.textAlignment = NSTextAlignmentCenter;
[lbl setBackgroundColor:[UIColor clearColor]];
lbl.font = [UIFont boldSystemFontOfSize:16];
[lbl setFrame:CGRectMake(20,112.5, 260, 75)];
[_imgView addSubview:lbl];
[_imgView bringSubviewToFront:lbl];
[_imgView setImage:img];
[_imgView.layer renderInContext:UIGraphicsGetCurrentContext()];
Counter = x+1;
NSLog(#"counter = %i",Counter);
switch (Counter) {
case 1:
NSLog(#"swintch case 1");
newImage1 = UIGraphicsGetImageFromCurrentImageContext();
break;
case 2:
NSLog(#"swintch case 2");
newImage2 = UIGraphicsGetImageFromCurrentImageContext();
break;
default:
break;
}
NSLog(#"after switch");
UIGraphicsEndImageContext();
}
//To save the picture in the album
UIImageWriteToSavedPhotosAlbum(newImage1, nil, nil, nil);
UIImageWriteToSavedPhotosAlbum(newImage2, nil, nil, nil);
NSLog(#"After the loop");
}
Also when I run this method on my iPhone it gives me a warning which is
CreatingVideo[334] : CGContextSaveGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
Your code doesn't make sense. You have a for loop that runs through an array, adds images to an image view, captures 1 of 2 images from the current off-screnen context, and then ends the image context after the first pass through the array. On the second pass, the context doesn't exist any more, so the second end context call will fail.
Move the end context outside of your for loop. That should fix your warning.
Even then, I'm not sure if it will work to remove subviews from an image view, add new views, an render the content to a graphics context, all without returning. UIKit view drawing usually queues changes to the UI until your code returns, then renders it on the next pass through the event loop.
Thanks to Duncan C for helping me find the answer and correct the code to work perfectly now
-(void)CreateTheImage{
UIImage * img = [UIImage imageNamed:#"SquareBackground.jpg"];
UIGraphicsBeginImageContextWithOptions(CGSizeMake(320, 320), NO, 0.0f);
int Counter = 0;
NSString *txt1 = #"Test";
NSString *txt2 = #"Worked Well";
[array addObject:txt1];
[array addObject:txt2];
UILabel *lbl = [[UILabel alloc]init];
NSLog(#"%i",[array count]);
NSLog(#"Before the loop");
for (int x = 0; x < [array count]; x++) {
for (UIView * view in [_imgView subviews]){
[view removeFromSuperview];
}
NSLog(#"Entered the loop");
NSLog(#"x = %i",x);
lbl.text = [array objectAtIndex:x];
NSLog(#"lbl.text = %#",[array objectAtIndex:x]);
lbl.textAlignment = NSTextAlignmentCenter;
[lbl setBackgroundColor:[UIColor clearColor]];
lbl.font = [UIFont boldSystemFontOfSize:25];
[lbl setFrame:CGRectMake(20,122.5, 280, 75)];
[_imgView addSubview:lbl];
[_imgView bringSubviewToFront:lbl];
[_imgView setImage:img];
[_imgView.layer renderInContext:UIGraphicsGetCurrentContext()];
Counter = x+1;
NSLog(#"counter = %i",Counter);
switch (Counter) {
case 1:
newImage1 = UIGraphicsGetImageFromCurrentImageContext();
NSLog(#"swintch case 1");
break;
case 2:
NSLog(#"swintch case 2");
newImage2 = UIGraphicsGetImageFromCurrentImageContext();
break;
default:
break;
}
NSLog(#"after switch");
}
UIGraphicsEndImageContext();
//To save the picture in the album
UIImageWriteToSavedPhotosAlbum(newImage1, nil, nil, nil);
UIImageWriteToSavedPhotosAlbum(newImage2, nil, nil, nil);
NSLog(#"After the loop");
}

Change Animation Speed Series of Images

I have a series of images, I want them to repeat. However, I want the first half to play in, for example 2 seconds, then the second half to play in 5 seconds.
It is quite easy to play a series of images, using the following
- (void) completeCycles:(int) cycles inhalePercentage:(int) inhalePercent exhalePercentage:(int) exhalePercent totalCycleTime:(int) time
{
NSMutableArray *textures = [NSMutableArray array];
for (int i = 0; i < kNumberBreathingImages; i++) {
NSString *textureName = [NSString stringWithFormat:#"breath%d.png", i];
for (int i = 0; i < inhalePercent; i++) {
[textures addObject:[UIImage imageNamed:textureName]];
}
}
for (int i = kNumberBreathingImages - 1; i > 0; i--) {
NSString *textureName = [NSString stringWithFormat:#"breath%d.png", i];
for (int i = 0; i < exhalePercent; i++) {
[textures addObject:[UIImage imageNamed:textureName]];
}
}
self.animationImageView.animationImages = textures;
self.animationImageView.animationDuration = time;
self.animationImageView.animationRepeatCount = cycles;
[self.animationImageView startAnimating];
}
However, I want the first half of the animation to take x time and the second half to take y time.
I don't think the above will allow me to do this, just wondering what a better approach would be.
Pretty sure will need to use
UIView animateWithDuration:animations: completion:
Thanks for any assistance.
This code creates this effect,
The animation system on UIImageView is very limited. I would suggest that you make your own implementation with say 2 image view.
You would than change the image in one imageview and the fade in and out using UIView animateWithDuration
I have written a method for you. Please note: I have not tested it.
It assumes you have your frames in a array called 'frames' and have two UIIMageView placed on top of each other called 'imgv1' and 'imgv2'
-(void)performAnimationOfFrameAtIndex:(NSNumber*)indexNum
{
int index = [indexNum intValue];
if(index >= frames.count)
{
return;
}
UIImage *img = [frames objectAtIndex:index];
UIImageView *imgIn;
UIImageView *imgOut;
if(index % 2 == 0)
{
imgIn = imgv1;
imgOut = imgv2;
}
else
{
imgIn = imgv2;
imgOut = imgv1;
}
imgIn.image = img;
[self.view sendSubviewToBack:imgIn];
[UIView animateWithDuration:0.1 animations:^
{
imgIn.alpha = 1;
imgOut.alpha = 0;
} completion:^(BOOL finished)
{
[self performSelectorOnMainThread:#selector(performAnimationOfFrameAtIndex:) withObject:[NSNumber numberWithInt:index+1] waitUntilDone:NO];
}];
}
Thanks for the idea,
I changed your code above to get the desired effect I wanted, now it works perfect. The alpha was causing a "strobe" effect even when the duration is 0 seconds.
Here is my final code
Enjoy the 100 :-)
- (void) performAnimationOfFrameAtIndex:(NSNumber*)indexNum
{
int index = indexNum.intValue;
if (index >= self.frames.count) return;
UIImage *img = self.frames[index];
UIImageView *imgIn;
UIImageView *imgOut;
float speed = (index <= self.frames.count / 2) ? 0.1 : 1; // first half : second half speed.
if (index % 2 == 0) {
imgIn = self.animationImageViewOne;
imgOut = self.animationImageViewTwo;
}
else {
imgIn = self.animationImageViewTwo;
imgOut = self.animationImageViewOne;
}
imgIn.image = img;
[self.view sendSubviewToBack:imgIn];
[self performSelector:#selector(performAnimationOfFrameAtIndex:) withObject:[NSNumber numberWithInt:index+1] afterDelay:speed];
}
I don't think the above will allow me to do this, just wondering what a better approach would be.
Actually, it will. You just need to repeat the images as you form the sequence. For the images in the first group, repeat each one twice before going on to the next one. For the images in the second group, repeat each one five times before going on to the next one. Now set the time for the total animation to 7 seconds. Since there are about the same number of images in each group originally, you can readily see that this means the first group will take about 2 seconds and the second group will take about 5 seconds.

UIView animationWithDuration recursive cause jitter

I tried to set the property as atomic but it doesn't seems to work anyway. Here's the code. It move a label displaying the song name being played. And sometime it start jittering as if the label was supposed to be at two places at the same time. Any clue ? Some lock property maybe...
- (void)animateSongLabel
{
if (!self.player.rate) {
[UIView animateWithDuration:.5 animations:^{
self.songLabel.left = 25.f;
}];
return;
}
[UIView animateWithDuration:.25 delay:0. options:UIViewAnimationOptionCurveLinear animations:^{
self.songLabel.left -= 15.f;
} completion:^(BOOL finished) {
if (self.songLabel.right < -10.f) {
self.songLabel.left = 320.f;
}
[self animateSongLabel];
}];
}
The rock-bottom simplest way to make text that just sits there and scrolls sideways is to display an animated UIImage or animated UIImageView - especially the former, because it animates forever, which is probably what you want. Generate the successive UIImage objects in code by drawing your text slightly offset each time, and hand them to animatedImageWithImages:duration:. Now wherever you show that image, it will be animating.
Here's some sample code to get you started (tweak to get precisely the effect you have in mind):
NSString* s = #"Mister Dobbalena, Mister Bob Dobbalena";
NSMutableArray* marr = [NSMutableArray array];
UIFont* f = [UIFont fontWithName:#"Helvetica" size:12];
float w = [s sizeWithFont:f].width;
for (int offset = 0; offset < w; offset++) {
UIGraphicsBeginImageContextWithOptions(self.iv.frame.size, NO, 0);
[s drawAtPoint:CGPointMake(10-offset,20) withFont:f];
[marr addObject: UIGraphicsGetImageFromCurrentImageContext()];
UIGraphicsEndImageContext();
}
UIImage* im = [UIImage animatedImageWithImages:marr duration:20];
self.iv.image = im;

How do I animate a sprite sheet in Xcode without Cocos2d?

I'm developing a simple application that animates an image as the user moves a slider. This could easily be done with individual images, but for obvious reasons that method is inefficient.
Currently, I have the animation broken up into 14 sprite sheets with 16 images per sheet. I created a method that uses CGImageCreateWithImageInRect to find the current image dictated by the slider and update the image view with that image. This works, but not fluidly. I think I understand why, but I have no clue what to do otherwise. While I could use Cocos2d or OpenGL ES, I am stubborn and convinced that this is possible without them. I just want to know how.
Here's some example code:
- (void)setUp{
NSString *string;
NSString *bundleString = [[NSBundle mainBundle] bundlePath];
dsRedPathArray = [[NSMutableArray alloc] initWithCapacity:15];
for (int i = 0; i < 14; i++)
{
string = [bundleString stringByAppendingFormat:#"/dsRedAni_%d.png", i];
[dsRedPathArray addObject:string];
}
//initial image starts at (0, 1) of image dsRedAni_9
currentImage = [UIImage imageWithContentsOfFile:[dsRedPathArray objectAtIndex:9]];
currentRef = CGImageCreateWithImageInRect(currentImage.CGImage, CGRectMake(495, 0, kModelWidth, kModelHeight));
modelView.image = [UIImage imageWithCGImage:currentRef];
}
- (IBAction)sliderMoved:(UISlider*)sender
{
[self animateModel:sender.value];
}
- (void)animateModel:(int)index
{
index += 1;
imageIndex = (index / 16) + 9;
if (imageIndex > 13)
{
imageIndex = -14 + imageIndex;
}
currentX = kModelWidth * (index % 4);
currentY = kModelHeight * ((index / 4) % 4);
currentRect = CGRectMake(currentX, currentY, kModelWidth, kModelHeight);
currentImage = [UIImage imageWithContentsOfFile:[dsRedPathArray objectAtIndex: (imageIndex)]];
currentRef = CGImageCreateWithImageInRect(currentImage.CGImage, currentRect);
modelView.image = [UIImage imageWithCGImage:currentRef];
}
Thanks in advance for any help.
I finally found a rather quick and efficient, if unconventional, way of cycling through each section of my sprite sheets without any outside help from APIs. Rather than spending time and power cutting up the image into contexts or individual files, I found that it was more efficient for me to create a UIView in the size of the image I needed and then adding the entire sprite sheet to the view as a UIImageView.
With view.clipsToBounds set to YES, the view acts as a mask for my sprite sheet, limiting the visible portion to the size of each image I want to cycle through on the sheet. In order to give the effect of animation, I simply use imageview.center to move the sprite sheet around the view to the desired image coordinates. So, in a sprite-sheet with 16 images I only have to make one call to show the image, then move it around per each frame in the animation.
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setUp];
self.backgroundColor = [UIColor clearColor];
self.clipsToBounds = YES;
}
return self;
}
- (void)setUp
{
//assign |lastImageIndex| a number not equal to |imageIndex|
lastImageIndex = -1;
modelImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1924, 1708)];
NSString *string;
NSString *bundleString = [[NSBundle mainBundle] bundlePath];
UIImage *image;
if (!imageArray)
{
imageArray = [[NSMutableArray alloc] init];
NSLog(#"Init egfp |imageArray|");
}
for (int i = 0; i < 10; i++)
{
string = [bundleString stringByAppendingFormat:#"/moleculeAni_%d.png", i];
image = [UIImage imageWithContentsOfFile:string];
[imageArray addObject:image];
if (i == 9)
{
NSLog(#"Filled egfp |imageCache|");
}
}
[self addSubview:modelImageView];
}
- (void)animateModel:(int)index
{
if (index != 1)
{
index -= 1;
}
imageIndex = (index / 16);
if (imageIndex < 9)
{
currentX = 962 - (481 * (index % 4));
currentY = 854 - (427 * ((index / 4) % 4));
}
else
{
currentX = 962 - (481 * (index % 4));
currentY = 427 - (427 * ((index / 4) % 4));
}
if (imageIndex != lastImageIndex)
{
if (imageIndex < 9 && onLastFrame)
{
modelImageView.frame = CGRectMake(0, 0, 1924, 1708);
onLastFrame = NO;
}
else if (imageIndex == 9 && !onLastFrame)
{
modelImageView.frame = CGRectMake(0, 0, 1924, 854);
onLastFrame = YES;
}
NSLog(#"Image: %d", imageIndex);
tempImage = [imageArray objectAtIndex:imageIndex];
modelImageView.image = tempImage;
}
modelImageView.center = CGPointMake(currentX, currentY);
lastImageIndex = imageIndex;
}
Most of the code here is spent determining where the imageview needs to move in order to display the correct image. This is taking the method I explained above and is spreading it across 10 sprite sheets each with 16 images spread evenly (except the last which has 8). The only slowdown came when the program was swapping between images every 16th frame. To get around this, my controller has the view quickly cycle through all the images beneath another view (like a curtain) so the user is only privy to a loading screen. Once the images have been cycled, the curtain view is removed and the animation (controlled by the user with a slider) moves like butter.
One way to do this would be to cut up the images with CGImageCreateWithImageInRect, like you started to above. Then, add them to an array:
myArray addObject:[UIImage imageWithCGImage:currentRef];
Next use a UIImageView with setAnimationImages, like this:
UIImageView *myAnimationImageView;
[myAnimationImageView setAnimationImages:myArray];
Then You can start the animation.
There is a good project doing this here: https://github.com/r3econ/UIImage-Sprite-Additions

Resources