我自己没有尝试过你的方式,但我也想创建一个自定义的相机视图。这可能不是您想要的,但它是一种替代方法。我与 .xib 文件一起创建了一个自定义 UIView。
在 .m 文件中,您只需将适当的委托方法调用到您实例化 imagePicker 的 ViewController。然后在此 ViewController 中调用适当的方法,例如takePicture
.
这样,您可以使用 xib 文件使覆盖看起来像您喜欢的任何方式。您可以实例化图像选择器
FALKCameraView.h :
@protocol CameraViewDelegate <NSObject>
- (void)cameraPressed;
- (void)buttonPressed;
//etc
@end
@interface FALKCameraView : UIView
@property (nonatomic, assign) NSObject<CameraViewDelegate> *delegate;
//Camera Button pressed- notifies CameraViewDelegate
- (IBAction)cameraPressed:(id)sender;
//Button pressed - notifies CameraViewDelegate
-(IBAction)buttonPressed:(id)sender;
@end
FALKCameraView.m:
@implementation FALKCameraView
@synthesize delegate;
- (IBAction)cameraPressed:(id)sender{
[delegate cameraPressed];
}
-(IBAction)buttonnPressed:(id)sender{
[delegate buttonPressed];
}
@end
FALKCameraViewController.h:
@interface FALKCameraViewController : UIViewController <UIImagePickerControllerDelegate, CameraViewDelegate>
- (void)cameraPressed;
- (void)buttonPressed;
@end
FALKCameraViewController.m:
@interface FALKCameraViewController
@property (strong,nonatomic) UIImagePickerController *imagePicker;
@end
@implementation FALKCameraViewController
@synthesise imagePicker;
-(void)setUpCamera{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera]){
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = NO;
imagePicker.allowsEditing = NO;
imagePicker.mediaTypes = @[(NSString *) kUTTypeImage];
NSString *nibName = @"FALKCameraView";
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:nibName
owner:nil
options:nil];
if([nibs count]){
id nib = [nibs objectAtIndex:0];
if([nib isKindOfClass:[FALKCameraView class]]){
FALKCameraView *view = (FALKCameraView*)nib;
view.delegate = self;
imagePicker.cameraOverlayView = view;
}
}
[self presentViewController:imagePicker
animated:NO completion:nil];
}
}
-(void)cameraPressed:(id)sender{
[imagePicker takePicture];
}
@end