编辑3
好消息和坏消息。 好消息是,在通过断开覆盖UIToolbar和连接的UIImageView的连接检查,我看到theKing
,但随后-坏消息-我没有看到UIToolbar,这也是我所需要的。 所以,现在的问题是,用户怎样才能找回时,他/她在这里完成了调用VC? 无论是工具栏和形象如何能成为覆盖的一部分,或者可以在“Go Back按钮”工具栏上的非重叠视图,还是什么? 或者,我怎样才能使这两个工具栏上OverlayViewController的形象展示?
编辑3
编辑2
setupImagePicker
在OverlayViewController.m
。
- (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,但我是读书马特·诺伊堡今天的书,他说UIImagePicker的工作方式不同的2个设备。
编辑0
我看不到我试图跨过UIImagePicker摄像机视图叠加图像。 无论我如何添加IBOutlet中,作为一个财产或没有时,图像不显示,但叠加工具栏显示罚款。 为什么?
OverlayViewController.h与theKing
IBOutlet中加入苹果的示例代码,然后注释掉现在。
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioServices.h>
@protocol OverlayViewControllerDelegate;
@interface OverlayViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
{
// IBOutlet UIImageView* theKing; ******** temporarily commented out
id <OverlayViewControllerDelegate> delegate;
}
@property (nonatomic, assign) id <OverlayViewControllerDelegate> delegate;
@property (nonatomic, retain) UIImagePickerController *imagePickerController;
- (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType;
@end
@protocol OverlayViewControllerDelegate
- (void)didTakePicture:(UIImage *)picture;
- (void)didFinishWithCamera;
@end
OverlayViewController.m与property
的theKing
IBOutlet中加入苹果的示例代码。
#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;
我看不到图像theKing
当我在iPhone上执行代码。 下面是我添加表示一些形成的连接的笔尖的视图。 不会引发任何错误,但我无法看到图像,只有UIToolbar已经添加。
更新
我现在已经更新,并试图复制你已经在你的问题做了什么。 我已经包含的.h / .M和完整的源theKing@2x.png
。 创建一个新的项目并粘贴到源文件,并添加theKing@2x.png
。 一切都进行编程 - 你不需要在除了导航控制器嵌入你的看法其它接口生成器来设置任何东西。
这里是theKing@2x.png
- http://i.imgur.com/0DrM7si.png
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@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:
。 我得想出一个办法来告诉我的用户这样做,但至少这将解雇图像查看和完成我的设置模式。 我真的想一个更清洁的替代,所以请,如果您有将它们添加答案。 感谢所有谁曾考虑我的问题。