2009-06-16 150 views
43

如何在相机预览中添加覆盖图(UIImageView)和 手柄触摸此?iPhone:相机预览覆盖

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

+85

真棒画画! – rpetrich 2009-06-17 00:29:31

+2

你最终解决了这个问题吗? – CodeAndCats 2009-09-07 10:41:10

回答

3

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

[window bringSubviewToFront:imageView]; 

照相机启动后。

如果你要处理的UIImageView触摸你可以只添加UIImageView作为一个正常的全屏View具有透明背景的一个子视图,并添加的窗口,而不是,与正常UIViewController子类,你可以用于处理触摸事件。

2

看到摄像头的覆盖图(3.1及更高版本)

@property(nonatomic, retain) UIView *cameraOverlayView 
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; 
    }