Pregunta

¿Cómo agrego una superposición ( UIImageView ) a la vista previa de la cámara y manejar toques en esto?

Mis intentos anteriores de hacer esto (por ejemplo, usar UIImagePickerController y agregar la imagen como una subvista) han fallado.

¿Fue útil?

Solución

Este tutorial lo explica: http://www.musicalgeometry.com/?p=821

Simplemente agrega un UIImage en la vista de superposición en lugar del área roja que se muestra en el tutorial.

Otros consejos

Para su archivo de implementación:

- (IBAction)TakePicture:(id)sender {

    // Create image picker controller
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

    // Set source to the camera
    imagePicker.sourceType =  UIImagePickerControllerSourceTypeCamera;

        // Delegate is self
        imagePicker.delegate = self;

        OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];     

        // Insert the overlay:
        imagePicker.cameraOverlayView = overlay;

       // Allow editing of image ?
        imagePicker.allowsImageEditing = YES;
        [imagePicker setCameraDevice:
        UIImagePickerControllerCameraDeviceFront];
        [imagePicker setAllowsEditing:YES];
        imagePicker.showsCameraControls=YES;
        imagePicker.navigationBarHidden=YES;
        imagePicker.toolbarHidden=YES;
        imagePicker.wantsFullScreenLayout=YES;

        self.library = [[ALAssetsLibrary alloc] init];

        // Show image picker
        [self presentModalViewController:imagePicker animated:YES];
    }

Haz una clase UIView y agrega este código

    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            // Initialization code


            // Clear the background of the overlay:
            self.opaque = NO;
            self.backgroundColor = [UIColor clearColor];

            // Load the image to show in the overlay:
            UIImage *overlayGraphic = [UIImage imageNamed:@"overlaygraphic.png"];
            UIImageView *overlayGraphicView = [[UIImageView alloc] initWithImage:overlayGraphic];
            overlayGraphicView.frame = CGRectMake(30, 100, 260, 200);
            [self addSubview:overlayGraphicView];

        }
        return self;
    }

Es posible que pueda agregar el UIImageView como una subvista de la ventana principal directamente en lugar del UIImagePicker , puede funcionar mejor. Solo asegúrese de agregarlos en el orden correcto, o llame a

[window bringSubviewToFront:imageView];

después de que la cámara esté encendida.

Si desea manejar los toques en UIImageView , simplemente puede agregar UIImageView como una subvista de una pantalla normal View con una transparencia en segundo plano, y agregue eso a la ventana en su lugar, con una subclase UIViewController normal que puede usar para manejar los eventos táctiles.

Ver la vista de superposición de la cámara (disponible en 3.1 y versiones posteriores)

@property(nonatomic, retain) UIView *cameraOverlayView
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top