2010-02-20 38 views

Trả lời

16

Tôi hỏi một câu hỏi tương tự here

Giải pháp của tôi là tạo ra một cái nhìn tùy chỉnh trên đầu trang của UIImagePickerControllerView mặc định.

Tôi đã tải về ví dụ Augmented Reality

Sau đó, bạn có thể sử dụng OverlayView.m và OverlayView.h bằng cách thêm chúng vào dự án của bạn: tôi đã chọn tùy chỉnh thanh công cụ, chọn và overlayView toàn cầu để tôi có thể truy cập chúng bất cứ nơi nào trong dự án.

Trong ViewController.h bạn

@class OverlayView; 

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

Tôi tạo ra các điều khiển của thanh công cụ nút camera và nút

// 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; 

Các hủy phương pháp

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

The (shootPictureMethod hủy):

-(void) shootPicture { 

    [picker takePicture]; 

} 

Để thoát mà không hiển thị xem trước chỉ bỏ qua những quan điểm sau khi chụp ảnh trong phương pháp didFinishPickingImage

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

[self dismissModalViewControllerAnimated:YES]; 
} 
+0

Trong ví dụ này, không phải là nút chụp ảnh nhỏ? – Chris

+0

.. bạn đá !! \ m/ – Zaraki

+0

@erastusnjuki Tôi đang gặp phải sự cố trong trường hợp iPad. Vấn đề là trong khi định vị lại thanh công cụ từ Portrait-to-Landscape và ngược lại, hiệu ứng định vị lại toolBar hiển thị rõ ràng (nghĩa là thanh công cụ đang được di chuyển từ vị trí này sang vị trí khác trong khung thời gian nhỏ). Làm thế nào để giải quyết vấn đề này? –

Các vấn đề liên quan