2012-09-13 19 views
1

我試圖給出一個UIImagePickerController的Overlay視圖,我在其中添加OverlayViewController's視圖作爲子視圖ViewController。但是,當我將應用程序轉儲到設備時,它顯示一個空白屏幕。ImagePickerController with cameraOverlayView不會添加到ViewController的視圖

我的代碼是在這裏:

ViewController.m

@interface ViewController() 

@property (nonatomic, retain) OverlayViewController *overlayViewController; 

@end 

@implementation ViewController 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

self.overlayViewController = 
[[[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil] autorelease]; 

// as a delegate we will be notified when pictures are taken and when to dismiss the image picker 
self.overlayViewController.delegate = self; 

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) 
{ 
    [self.overlayViewController setupImagePicker:UIImagePickerControllerSourceTypeCamera]; 
    [self presentModalViewController:self.overlayViewController.imagePickerController animated:YES]; 
} 

// Do any additional setup after loading the view, typically from a nib. 
} 

OverlayViewController.m

@interface OverlayViewController() 
@property (nonatomic, retain) IBOutlet UIButton *Capture; 
@property (nonatomic, retain) IBOutlet UIButton *Library; 
@property (nonatomic, retain) IBOutlet UIButton *ZoomOut; 
@property (nonatomic, retain) IBOutlet UIButton *FrontCam; 
@property (nonatomic, retain) IBOutlet UISlider *zoom; 

@end 

@implementation OverlayViewController 
@synthesize delegate; 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 
    // Custom initialization 

    self.imagePickerController = [[UIImagePickerController alloc] init]; 

    self.imagePickerController.delegate = self; 

} 
return self; 
} 

- (void)dealloc 
{ 

[_imagePickerController release]; 

[super dealloc]; 
} 

- (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType 
{ 
self.imagePickerController.sourceType = sourceType; 

if (sourceType == UIImagePickerControllerSourceTypeCamera) 
{ 
    // user wants to use the camera interface 
    // 
    self.imagePickerController.showsCameraControls = NO; 

    if ([[self.imagePickerController.cameraOverlayView subviews] count] == 0) 
    { 
     // setup our custom overlay view for the camera 
     // 
     // ensure that our custom view's frame fits within the parent frame 
     CGRect overlayViewFrame = self.imagePickerController.cameraOverlayView.frame; 

     NSLog(@"Overlay view Frame heidgt is %f and width is %f", self.imagePickerController.cameraOverlayView.frame.size.height,self.imagePickerController.cameraOverlayView.frame.size.width); 


     CGRect newFrame = CGRectMake(0.0, 20.0, 320.0, 480.0); 

     NSLog(@"Overlay view Frame heidgt is %f and width is %f", self.view.frame.size.height,self.view.frame.size.width); 

     self.view.frame = newFrame; 

     [self.imagePickerController.cameraOverlayView addSubview:self.view]; 

    } 
} 
} 

我已經下載示例代碼https://developer.apple.com/library/ios/#samplecode/PhotoPicker/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010196做到這一點。

我想用一些控件(捕捉按鈕,閃光按鈕等)來呈現自定義視圖。我怎樣才能做到這一點..?

回答

0

只需將

self.backgroundColor = [UIColor clearColor]; 
self.opaque = NO; 

overlayViewinitWithFrame方法,並使用它:

CGRect crossFrame = CGRectMake(self.view.bounds.size.width/2.0-50, self.view.bounds.size.height/2.0-50, 100, 100); 
UIView *crosshairView = [[BNRCameraCrosshair alloc]initWithFrame:crossFrame]; 
imagePicker.cameraOverlayView = crosshairView; 
相關問題