views:

405

answers:

1

Like the title says, in the iPhone SDK, I want to create an animated UIImageView and use it as a camera overlay. However, nothing appears. I've been using the same setup to display a static image as an overlay, but when trying to use the following code, no overlay appears:

imageView.animationImages = [NSArray arrayWithObjects:
                                     [UIImage imageNamed:@"cameraScreenOverlay1.png"],
                                     [UIImage imageNamed:@"cameraScreenOverlay2.png"],
                                     [UIImage imageNamed:@"cameraScreenOverlay3.png"],
                                     [UIImage imageNamed:@"cameraScreenOverlay4.png"],
                                     [UIImage imageNamed:@"cameraScreenOverlay4.png"],
                                     [UIImage imageNamed:@"cameraScreenOverlay4.png"],
                                     [UIImage imageNamed:@"cameraScreenOverlay3.png"],
                                     [UIImage imageNamed:@"cameraScreenOverlay2.png"],
                                     [UIImage imageNamed:@"cameraScreenOverlay1.png"],
                                     nil];
        imageView.animationDuration = 1.0;
        imageView.animationRepeatCount = 0;
        [imageView startAnimating];

I know the above code works when the imageView is not used as an overlay. Any thoughts? Is this just a limitation of the current SDK?

A: 

I am trying to do the same thing. It will work when its just an overlay image, but once I try to animate with an array of images, nothing shows.

I was loading the pngs all wrong with imageWithContentsOfFile. It wont load the image it its just the image file. It needs the actual path. Try this something like this:

   NSArray *animationImages = [NSArray arrayWithObjects:
                                [UIImage imageWithContentsOfFile:[[ NSBundle mainBundle] pathForResource:@"back1" ofType:@"png"]],
                                [UIImage imageWithContentsOfFile:[[ NSBundle mainBundle] pathForResource:@"back2" ofType:@"png"]],
                                [UIImage imageWithContentsOfFile:[[ NSBundle mainBundle] pathForResource:@"back3" ofType:@"png"]],
                                [UIImage imageWithContentsOfFile:[[ NSBundle mainBundle] pathForResource:@"back4" ofType:@"png"]],
                                [UIImage imageWithContentsOfFile:[[ NSBundle mainBundle] pathForResource:@"back5" ofType:@"png"]],
                                [UIImage imageWithContentsOfFile:[[ NSBundle mainBundle] pathForResource:@"back6" ofType:@"png"]],
                                [UIImage imageWithContentsOfFile:[[ NSBundle mainBundle] pathForResource:@"back7" ofType:@"png"]],nil];


    imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
    imageview.animationImages = [animationImages retain] ;
    imageview.animationRepeatCount = 0;
    imageview.animationDuration= 1;

    [overlay.view addSubview:imageview]; 

    [moviePlayerWindow addSubview:overlay.view]; 
Tyler