2010-02-20 59 views

回答

16

我問過類似的問題here

我的解決方案是創建在默認UIImagePickerControllerView頂部的自定義視圖。

我下載的例子Augmented Reality

然後你可以將它們添加到您的項目中使用OverlayView.m和OverlayView.h: 我所做的自定義工具欄選擇器,選擇器和OverlayView的全球,這樣我可以訪問它們項目中的任何地方。

在你ViewController.h

@class OverlayView; 

@interface ViewController //bla bla... 
{ 
UIImagePickerController * picker; 
UIToolbar *toolBar; 
OverlayView *overlayView; 
} 

我創建工具欄的控制相機按鈕和取消按鈕

// toolbar - handy if you want to be able to exit from the image picker... 
      toolBar=[[[UIToolbar alloc] initWithFrame:CGRectMake(0, 480-55, 320, 55)] autorelease]; 
      toolBar.barStyle = UIBarStyleBlackOpaque; 
      NSArray *items=[NSArray arrayWithObjects: 
          [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelPicture)] autorelease], 
          [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease], 
          [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(shootPicture)] autorelease], 
          [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease], 
          [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease], 
          nil]; 
      [toolBar setItems:items]; 

      // create the overlay view 
      overlayView=[[[OverlayView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-44)] autorelease]; 
      // important - it needs to be transparent so the camera preview shows through! 
      overlayView.opaque=NO; 
      overlayView.backgroundColor=[UIColor clearColor]; 

        // parent view for our overlay 
     UIView *parentView=[[[UIView alloc] initWithFrame:CGRectMake(0,0,320, 480)] autorelease]; 
     [parentView addSubview:overlayView]; 
     [parentView addSubview:toolBar]; 

     // configure the image picker with our overlay view 
     picker=[[UIImagePickerController alloc] init]; 
     picker.sourceType = UIImagePickerControllerSourceTypeCamera; 

     // hide the camera controls 
     picker.showsCameraControls=NO; 
     picker.wantsFullScreenLayout = YES; 

的取消方法

- (IBAction)cancel { 
    // Don't pass current value to the edited object, just pop. 
    [self.navigationController popViewControllerAnimated:YES]; 
} 

的(shootPictureMethod ):

-(void) shootPicture { 

    [picker takePicture]; 

} 

退出而不表示預覽只是駁回拍攝照片在didFinishPickingImage方法

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo 
{ 
//do whatever 

[self dismissModalViewControllerAnimated:YES]; 
} 
+0

在這個例子中的後視圖,是不是按扣圖片按鈕小? – Chris 2011-04-30 18:07:53

+0

..你搖滾! \ m/ – Zaraki 2012-04-05 10:21:30

+0

@erastusnjuki我在iPad上遇到了一個問題。問題是,在從縱向到橫向重新定位工具欄時,反之亦然,工具欄重新定位效果清晰可見(即工具欄正在以小時間段從一個位置移動到另一個位置)。如何解決這個問題? – 2013-12-11 14:18:42

相關問題