我正在尝试在其上呈现UIImagePickerController
带有叠加视图的视图。我正在将OverlayViewController's
视图作为子视图添加到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下载了示例代码来执行此操作。
我想展示一个带有一些控件(捕获按钮、闪光按钮......等)的自定义视图。我怎样才能做到这一点..?