我在互联网上搜索了解决方案,但不幸的是我无法找到解决问题的方法。
大多数人都在创建UIImagePickerController
类的对象,但我决定以不同的方式来做这件事。
我创建了一个新类CameraViewController
,这个类扩展了UIImagePickerController
.
我的 .h 文件:
#import <UIKit/UIKit.h>
@interface CameraViewController : UIImagePickerController <UIImagePickerControllerDelegate>
-(void)captureImage;
@end
我的 .m 文件:
#import "CameraViewController.h"
#define CAMERA_TRANSFORM_X 1
#define CAMERA_TRANSFORM_Y 1.5
@interface CameraViewController ()
@end
@implementation CameraViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
UIButton *btnCapture = [[UIButton alloc] initWithFrame:CGRectMake((320/2)-(76/2), 480, 76, 76)];
[btnCapture setImage:[UIImage imageNamed:@"cam.png"] forState:UIControlStateNormal];
[btnCapture addTarget:self action:@selector(captureImage) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:btnCapture];
self.sourceType = UIImagePickerControllerSourceTypeCamera;
self.showsCameraControls = NO;
self.navigationBarHidden = YES;
self.wantsFullScreenLayout = YES;
self.cameraViewTransform = CGAffineTransformScale(self.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);
self.cameraOverlayView = view;
//[self openCamera];
// Do any additional setup after loading the view.
}
-(void)takePicture //overwrite take picture method
{
[super takePicture];
NSLog(@"%@", self);
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSLog(@"%@", info);
}
-(void)captureImage
{
[self takePicture];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
我实现了 delegate UIImagePickerControllerDelegate
。但似乎imagePickerController
由于某种原因没有调用 my 。在这种方法中,我尝试记录一个NSDirectory
. 所以我想也许我可以通过覆盖该takePicture
方法来获得我的图像,但我不知道如何。有谁知道如何帮助我?非常感谢