views:

551

answers:

0

Hi, I've made an animation over the camera and all works fine. I can start the camera, move the image in overlay, and save it as a picture.

My problem is that in the "preview" the animation keeps on moving, and I don't know when camera enters in this mode. I don't know how to check a bool or do something that can stop overlay.

Is there any way to skeep preview? Or does it exist some function that shows me the camera state?

Thanks for your time.

// camera declaration
{
 UIImagePickerController *imagePicker;

 imagePicker = [[UIImagePickerController alloc] init];
 imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
 imagePicker.delegate = self;
 imagePicker.showsCameraControls = YES;
 imagePicker.navigationBarHidden = YES;
 imagePicker.toolbarHidden = YES;

 imagePicker.cameraOverlayView = overlayView;

 [self presentModalViewController:imagePicker animated:YES];
 [self.view bringSubviewToFront:overlayView];
}



// animation
UIImageView *ani1;
ani1 = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ani1.png"]] autorelease];
[self.overlayView addSubview:ani1];

// loop for animation
[NSTimer scheduledTimerWithTimeInterval:0.05f target:self selector:@selector(loop) userInfo:nil repeats:YES];


-(void)loop {
// move x y each loop
newFrame = CGRectMake(x, y, 320, 480);
[ani1 setFrame:newFrame];
}



// camera finish
// take photo + overlay and save it
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
imagePicker.showsCameraControls = NO;
[self presentModalViewController:imagePicker animated:NO];
[self.view bringSubviewToFront:overlayView];

UIGraphicsBeginImageContext(picker.view.bounds.size);
[picker.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *newImage;
newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil);
}