带有cameraOverlayView的ImagePickerController没有添加到ViewController的View中

时间:2012-09-13 12:14:53

标签: iphone ios5 uiimagepickercontroller camera-overlay

我正在尝试在其上显示带有叠加视图的UIImagePickerController。我正在将OverlayViewController's视图作为子视图添加到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下载了示例代码来执行此操作。

我想在其上呈现一些自定义视图,其中包含一些控件(捕获按钮,闪光按钮......等)。我怎么能实现这个......?

1 个答案:

答案 0 :(得分:0)

放置

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

在您initWithFrame的{​​{1}}方法中,并使用它:

overlayView