我正在创建一个示例应用,可以使用自定义按钮捕获图像和录制视频。
我创建了一个UIImagePicker控制器的实例并分配了委托,但所有操作都已完成,但takePicture
没有调用委托方法。
我也提到了一些帖子UIImagePickerController takePicture not responding和UIImagepickerController [takepicture] modal view disappears no delegate callback,但没有得到我的解决方案。
这是我的代码。如果我遗失任何内容,请告诉我:
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.hidden = YES;
imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setAllowsEditing:NO];
[imagePicker setMediaTypes:[NSArray arrayWithObject:@"public.movie"]];
[imagePicker setCameraCaptureMode:UIImagePickerControllerCameraCaptureModeVideo];
[imagePicker setShowsCameraControls:NO];
[imagePicker setToolbarHidden:YES];
[imagePicker setDelegate:self];
UIView *overlayView = [[UIView alloc] initWithFrame:[[imagePicker view]frame]];
[overlayView setBackgroundColor:[UIColor clearColor]];
UIButton *btnCapture = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnCapture setFrame:CGRectMake(0, overlayView.frame.origin.y + overlayView.frame.size.height - 35, 30, 30)];
[btnCapture setTitle:@"c" forState:UIControlStateNormal];
[btnCapture addTarget:self action:@selector(captureFrame:) forControlEvents:UIControlEventTouchUpInside];
UIButton *btnStopVideo = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnStopVideo setFrame:CGRectMake(40, overlayView.frame.origin.y + overlayView.frame.size.height - 35, 30, 30)];
[btnStopVideo setTitle:@"s" forState:UIControlStateNormal];
[btnStopVideo addTarget:self action:@selector(btnStopTapped:) forControlEvents:UIControlEventTouchUpInside];
[overlayView addSubview:btnStopVideo];
[overlayView addSubview:btnCapture];
[imagePicker setCameraOverlayView:overlayView];
[self presentModalViewController:imagePicker animated:NO];
}
- (void)captureFrame:(id)sender {
[imagePicker takePicture];
}
但委托方法:- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
未被调用。
请帮我解决这个问题。
感谢所有
答案 0 :(得分:3)
只需添加此行
即可 picker.showsCameraControls = NO;
答案 1 :(得分:0)
您需要确保在标题中实施UIImagePickerControllerDelegate
协议。
@interface MyViewController <UIImagePickerControllerDelegate>
{
//
}
@end
答案 2 :(得分:0)
最好检查你的UIImagePickerController.delegate是否还是你的控制器。