質問

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

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

役に立ちましたか?

解決

このチュートリアルでは、 http://www.musicalgeometry.com/?p=821

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

他のヒント

実装ファイルの場合:

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

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

[window bringSubviewToFront:imageView];

カメラの起動後。

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

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

@property(nonatomic, retain) UIView *cameraOverlayView
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top