相机叠加图片

编辑3

好消息和坏消息。 好消息是,在Connections Inspector中,通过断开覆盖UIToolbar并连接UIImageview,我看到了theKing ,但后来 – 坏消息 – 我没有看到UIToolbar,我也需要它。 所以现在的问题是,当用户在这里完成时,用户如何回到调用VC? 如何将工具栏和图像都作为叠加层的一部分,或者“返回按钮”工具栏是否可以位于非叠加视图上,或者其他什么? 或者如何在OverlayViewController上显示工具栏和图像?

编辑3

编辑2

OverlayViewController.m setupImagePicker

 - (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; CGRect newFrame = CGRectMake(0.0, CGRectGetHeight(overlayViewFrame) - self.view.frame.size.height - 10.0, CGRectGetWidth(overlayViewFrame), self.view.frame.size.height + 10.0); self.view.frame = newFrame; [self.imagePickerController.cameraOverlayView addSubview:self.view]; } } } 

编辑2

编辑1

这是PhotoPicker示例代码链接 。

编辑1

编辑0

有没有人在iPhone而不是iPad上试过这个? 我没有iPhone,但我今天正在阅读Matt Neuburg的书,他说UIImagePicker在2台设备上的工作方式不同。

编辑0

我无法在UIImagePicker中看到我试图覆盖整个摄像机视图的图像。 无论我如何添加IBOutlet,作为属性与否,图像都不会显示,但覆盖的工具栏显示正常。 为什么?

将带有theKing IBOutlet的OverlayViewController.h添加到Apple的示例代码中,然后theKing注释掉。

 #import  #import  @protocol OverlayViewControllerDelegate; @interface OverlayViewController : UIViewController  { // IBOutlet UIImageView* theKing; ******** temporarily commented out id  delegate; } @property (nonatomic, assign) id  delegate; @property (nonatomic, retain) UIImagePickerController *imagePickerController; - (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType; @end @protocol OverlayViewControllerDelegate - (void)didTakePicture:(UIImage *)picture; - (void)didFinishWithCamera; @end 

theKingtheKing IBOutlet的property添加到Apple的示例代码中。

 #import "OverlayViewController.h" enum { kOneShot, // user wants to take a delayed single shot kRepeatingShot // user wants to take repeating shots }; @interface OverlayViewController ( ) @property (assign) SystemSoundID tickSound; @property (nonatomic, retain) IBOutlet UIImageView* theKing; // added ********* @property (nonatomic, retain) IBOutlet UIBarButtonItem *takePictureButton; @property (nonatomic, retain) IBOutlet UIBarButtonItem *startStopButton; @property (nonatomic, retain) IBOutlet UIBarButtonItem *timedButton; @property (nonatomic, retain) IBOutlet UIBarButtonItem *cancelButton; @property (nonatomic, retain) NSTimer *tickTimer; @property (nonatomic, retain) NSTimer *cameraTimer; 

当我在iPhone上执行代码时,我看不到图像theKing 。 下面是我添加的笔尖视图,显示了一些连接。 没有错误,但我看不到图像,只添加了UIToolbar。

覆盖控制器的笔尖

更新

我现在更新了它并尝试复制你在问题中所做的事情。 我已经包含.h / .m和theKing@2x.png完整来源。 创建一个新项目并将源粘贴到文件中并添加theKing@2x.png 。 一切都是以编程方式完成的 – 除了将视图嵌入导航控制器之外,您无需在界面构建器中设置任何内容。

这是theKing@2x.pnghttp://i.imgur.com/0DrM7si.png

ViewController.h

 #import  @interface ViewController : UIViewController  @end 

ViewController.m

 #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // assign action to button UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; myButton.frame = CGRectMake(0, 0, 200, 60); myButton.center = self.view.center; [myButton addTarget:self action:@selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside]; [myButton setTitle:@"Image Picker" forState:UIControlStateNormal]; [self.view addSubview:myButton]; } - (void)buttonPress:(id)sender { if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { // alert the user that the camera can't be accessed UIAlertView *noCameraAlert = [[UIAlertView alloc] initWithTitle:@"No Camera" message:@"Unable to access the camera!" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil]; [noCameraAlert show]; } else { // prepare imagePicker view UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker.delegate = self; imagePicker.allowsEditing = NO; imagePicker.showsCameraControls = NO; // create view for overlay CGRect overlayRect = CGRectMake(0, 0, imagePicker.view.frame.size.width, imagePicker.view.frame.size.height); UIView *overlayView = [[UIView alloc] initWithFrame:overlayRect]; // prepare the image to overlay UIImageView *overlayImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"theKing"]]; overlayImage.center = overlayView.center; overlayImage.alpha = 0.5; // prepare toolbar for overlay UIToolbar *overlayToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 600, overlayView.frame.size.width, 40)]; overlayToolbar.center = CGPointMake(overlayView.center.x, overlayView.frame.size.height - 20); overlayToolbar.barStyle = UIBarStyleBlack; UIBarButtonItem *takePictureButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(takePictureButtonPressed:)]; UIBarButtonItem *flexibleBarSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; flexibleBarSpace.width = 1000; UIBarButtonItem *startStopButton = [[UIBarButtonItem alloc] initWithTitle:@"Snap" style:UIBarButtonItemStyleBordered target:self action:@selector(startStopButtonPressed:)]; UIBarButtonItem *timedButton = [[UIBarButtonItem alloc]initWithTitle:@"Timed" style:UIBarButtonItemStyleBordered target:self action: @selector(timedButtonPressed:)]; UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action: @selector(cancelButtonPressed:)]; overlayToolbar.items = [NSArray arrayWithObjects:takePictureButton, flexibleBarSpace, startStopButton, timedButton, cancelButton, nil]; [overlayView addSubview:overlayImage]; [overlayView addSubview:overlayToolbar]; // add the image as the overlay [imagePicker setCameraOverlayView:overlayView]; // display imagePicker [self.navigationController presentViewController:imagePicker animated:YES completion:nil]; } } #pragma mark - UIBarButton Selectors - (void)takePictureButtonPressed:(id)sender { NSLog(@"takePictureButtonPressed..."); // TODO: take picture! } - (void)startStopButtonPressed:(id)sender { NSLog(@"startStopButtonPressed..."); // TODO: make this do something } - (void)timedButtonPressed:(id)sender { NSLog(@"timedButtonPressed..."); // TODO: implement timer before calling takePictureButtonPressed } - (void)cancelButtonPressed:(id)sender { NSLog(@"cancelButtonPressed"); [self.navigationController dismissViewControllerAnimated:YES completion:nil]; } #pragma mark - UIImagePickerController Delegate Methods - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)editingInfo { // determine if the user selected or took a new photo UIImage *selectedImage; if ([editingInfo objectForKey:UIImagePickerControllerOriginalImage]) selectedImage = (UIImage *)[editingInfo objectForKey:UIImagePickerControllerOriginalImage]; else if ([editingInfo objectForKey:UIImagePickerControllerEditedImage]) selectedImage = (UIImage *)[editingInfo objectForKey:UIImagePickerControllerEditedImage]; // TODO: Do something with selectedImage (put it in a UIImageView // dismiss the imagePicker [picker.presentingViewController dismissViewControllerAnimated:YES completion:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end 

截图

这就是我运行时的样子。 截图

这是否满足您的应用程序要求?

我找到的一个答案是将图像放在一个巨大的按钮上,该按钮具有以下动作Done: 。 我必须想办法告诉我的用户这样做,但至少这会解雇图像视图并完成我的设置模式。 我真的想要一个更清洁的替代品,所以如果你有它们,请添加答案。 感谢所有考虑过我的问题的人。