如何在相机预览中添加叠加( UIImageView ) 处理这个问题?

我之前尝试这样做(例如使用 UIImagePickerController 并将图像添加为子视图)失败。

其他提示

对于您的实施文件:

- (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];
    }

创建一个UIView类并添加此代码

    - (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;
    }

您可以直接添加 UIImageView 作为主窗口的子视图,而不是 UIImagePicker ,它可能会更好。只需确保按正确的顺序添加它们,或致电

[window bringSubviewToFront:imageView];
相机启动后

如果你想处理 UIImageView 上的触摸,你可以添加 UIImageView 作为普通全屏 View 的子视图,透明使用普通的 UIViewController 子类,将那个添加到窗口中,您可以使用它来处理触摸事件。

请参阅相机叠加视图(3.1及更高版本中提供)

@property(nonatomic, retain) UIView *cameraOverlayView
scroll top