2009-06-16 153 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; 
    }