开发者

Using an animated UIImageView as an iPhone camera overlay

开发者 https://www.devze.com 2022-12-21 04:56 出处:网络
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

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 开发者_Python百科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?


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]; 
0

精彩评论

暂无评论...
验证码 换一张
取 消