43

UIImageViewカメラ プレビューにオーバーレイ ( ) を追加し、これに対するタッチを処理するにはどうすればよいですか?

これを行う以前の試み (たとえばUIImagePickerController、画像をサブビューとして使用および追加する) は失敗しました。

4

4 に答える 4

37

このチュートリアルで説明しています: http://www.musicalgeometry.com/?p=821

チュートリアルに示されている赤い領域の代わりに、オーバーレイ ビューに UIImage を追加するだけです。

于 2010-01-12T13:06:31.173 に答える
10

実装ファイルの場合:

- (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;
    }
于 2012-11-06T12:07:31.597 に答える
3

UIImageViewの代わりに、メインウィンドウのサブビューとしてを直接追加できる場合がありUIImagePickerます。正しい順序で追加するか、電話してください

[window bringSubviewToFront:imageView];

カメラが上がった後。

上のタッチを処理する場合はUIImageView、背景が透明なUIImageView通常のフルスクリーンのサブビューとしてを追加、代わりに、タッチイベントの処理に使用できる通常のサブクラスを使用してウィンドウに追加できます。ViewUIViewController

于 2009-06-16T13:28:41.290 に答える
2

カメラ オーバーレイ ビューを表示する (3.1 以降で使用可能)

@property(nonatomic, retain) UIView *cameraOverlayView
于 2011-02-08T17:45:53.240 に答える