UIImageView won't animate with UIImages of CGImage

Discussion in 'iOS Programming' started by gwelmarten, Oct 6, 2013.

  1. gwelmarten macrumors 6502

    Joined:
    Jan 17, 2011
    Location:
    England!
    #1
    I have a UIImageView that I am trying to make do an animation of a set of UIImages that are created by flipping other UIImages. Here's my code:
    Code:
        turtle = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width-200,
                                                                        self.view.frame.size.height - sand.frame.size.height - turtle.frame.size.height - 10 - heightOfKeyboard,
                                                                        100,100)];
    [flippedTurtleArray addObject:[UIImage imageWithCGImage:[UIImage imageNamed:@"Turtle1.png"].CGImage scale:1 orientation:UIImageOrientationDownMirrored]];
    [flippedTurtleArray addObject:[UIImage imageWithCGImage:[UIImage imageNamed:@"Turtle2.png"].CGImage scale:1 orientation:UIImageOrientationDownMirrored]];
    [flippedTurtleArray addObject:[UIImage imageWithCGImage:[UIImage imageNamed:@"Turtle3.png"].CGImage scale:1 orientation:UIImageOrientationDownMirrored]];
    [flippedTurtleArray addObject:[UIImage imageWithCGImage:[UIImage imageNamed:@"Turtle2.png"].CGImage scale:1 orientation:UIImageOrientationDownMirrored]];
    [self.view addSubview: turtle];
    
    Problem is, when I try and make it animate from the array of flipped images, it shows the originals, not the flipped ones (i.e., when I do this):
    Code:
    turtle.animationImages = flippedTurtleArray;
    turtle.animationDuration = 0.8f;
    turtle.animationRepeatCount = 0;
    [turtle startAnimating];
    the original non flipped images are shown.
    
    Now, if I do this however:
    Code:
    turtle.image = [flippedTurtleArray objectAtIndex:1];
    the flipped image is shown. I thought maybe you can't do the animation with CGImage, but couldn't find that anyone else had had the same problem. Any ideas?

    Thanks,

    Sam
     
  2. xArtx macrumors 6502a

    Joined:
    Mar 30, 2012
    #2
    Not the same problem, but something similarly strange is I tried
    to make sixteen arrow frames pointing in all directions.
    I can only get it down to five original frames required as pngs,
    because once I've created a UIimage from another UIImage that is flipped,
    no more images can be created by flipping the result UIImage a second time.

    Code:
        arrowestImage = [UIImage imageNamed:@"arrowest.PNG"];
        arrowneImage = [UIImage imageNamed:@"arrowne.PNG"];
        arrownthImage = [UIImage imageNamed:@"arrownth.PNG"];
        arroweneImage = [UIImage imageNamed:@"arrowene.PNG"];
        arrownneImage = [UIImage imageNamed:@"arrownne.PNG"];
            
        arrowseImage = [UIImage imageWithCGImage:arrowneImage.CGImage scale:1.0 orientation: UIImageOrientationDownMirrored];
        arroweseImage = [UIImage imageWithCGImage:arroweneImage.CGImage scale:1.0 orientation: UIImageOrientationDownMirrored];
        arrowsseImage = [UIImage imageWithCGImage:arrownneImage.CGImage scale:1.0 orientation: UIImageOrientationDownMirrored];
        arrowsthImage = [UIImage imageWithCGImage:arrownthImage.CGImage scale:1.0 orientation: UIImageOrientationDown];
        arrowwstImage = [UIImage imageWithCGImage:arrowestImage.CGImage scale:1.0 orientation: UIImageOrientationUpMirrored];
        arrowswImage = [UIImage imageWithCGImage:arrowneImage.CGImage scale:1.0 orientation: UIImageOrientationDown];
        arrownwImage = [UIImage imageWithCGImage:arrowneImage.CGImage scale:1.0 orientation: UIImageOrientationUpMirrored];
        arrowwswImage = [UIImage imageWithCGImage:arroweneImage.CGImage scale:1.0 orientation: UIImageOrientationDown];
        arrowwnwImage = [UIImage imageWithCGImage:arroweneImage.CGImage scale:1.0 orientation: UIImageOrientationUpMirrored];
        arrownnwImage = [UIImage imageWithCGImage:arrownneImage.CGImage scale:1.0 orientation: UIImageOrientationUpMirrored];
        arrowsswImage = [UIImage imageWithCGImage:arrownneImage.CGImage scale:1.0 orientation: UIImageOrientationDown];
    
    This is as few pngs I could begin with to get all sixteen direction arrows.
    It's like North, South, then North-West, South-West, then down to South-South-West, and North-North-East.

    Logically, it should be possible with three images if you can rotate in any 90 degree increment.
     

Share This Page