问题描述
我正在使用带有自定义叠加层的UIImagePickerController在我的应用中录制视频。为了实现UIImagePickerController,我使用了
I am using UIImagePickerController with a custom overlay to record a video in my app. For the implementation of the UIImagePickerController, I have used the code from a great Ray Wenderlich tutorial.
我隐藏了相机的控件,并创建了一个简单的自定义叠加视图。这已经工作并加载很好。
然后我为视图创建了一个工具栏和按钮,用于录制视频:
I have hidden the controls for the camera, and created a simple custom overlay view. This has worked and loads fine.I have then created a toolbar and buttons for the view, to record the video:
- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate {
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
// Displays a control that allows the user to choose movie capture
cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
cameraUI.allowsEditing = NO;
cameraUI.delegate = delegate;
//Overlay view and toolbar setup
// creating overlayView
UIView* overlayView = [[UIView alloc] initWithFrame:cameraUI.view.frame];
// letting png transparency be
float width = 320;
float AR = (4.0/3.0);
float toolbar_height = 480 - (AR*width);
UIToolbar *toolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, (AR*width), 320, toolbar_height)];
//toolBar.tintColor = [UIColor colorWithRed:(252/255.) green:(0/255.) blue:(48/255.) alpha:1];
toolBar.tintColor = [UIColor colorWithRed:(49/255.) green:(52/255.) blue:(49/255.) alpha:1];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *RecordBarButtonItem = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(recordPressed:)];
UIBarButtonItem *CancelBarButtonItem = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(imagePickerControllerDidCancel:)];
NSArray *buttons = [NSArray arrayWithObjects: CancelBarButtonItem, flexibleSpace, RecordBarButtonItem, flexibleSpace, nil];
[toolBar setItems: buttons animated:NO];
[overlayView addSubview:toolBar];
[overlayView.layer setOpaque:NO];
overlayView.opaque = NO;
cameraUI.showsCameraControls = NO;
cameraUI.cameraOverlayView = overlayView;
[controller presentViewController: cameraUI animated: YES completion:nil];
return YES;
}
我的按钮 recordBarButtonItem 调用 recordPressed 由下式给出:
My button recordBarButtonItem calls recordPressed which is given by:
- (void) recordPressed: (UIImagePickerController *) picker {
NSLog(@"lets record");
[picker startVideoCapture];
}
所以'let record'出现在日志中,但是我收到了NSInvalidArgumentException startVideoCapture的错误。我知道我试图通过按钮按下开始视频捕获的方式有明显错误,但我无法弄明白。如果解决方案很简单,在iOS上还是相当新手,请原谅我!
干杯,
迈克
So the 'lets record' appears on the log, but I receive an NSInvalidArgumentException error for the startVideoCapture. I know theres something obviously wrong with the way im trying to start the video capture through the button press, but I cant figure it out. Still quite a novice at iOS so forgive me if the solution is simple!Cheers,Mike
推荐答案
问题在于您附加到<$ c $的操作c> initWithBarButtonSystemItem 调用不会传递 UIImagePickerController
实例。
The problem is that the action you attach to the initWithBarButtonSystemItem
call doesn't pass the UIImagePickerController
instance along.
我是什么我会做的是将UIImagePickerController设置为你的类的属性并从你的动作中访问该属性,如下所示:
What I would do is set the UIImagePickerController as a property of your class and access that property from your action, like this:
在你的.h:
@property (nonatomic, strong) UIImagePickerController *cameraUI;
在你的.m:
- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate {
...
self.cameraUI = [[UIImagePickerController alloc] init];
...
UIBarButtonItem *RecordBarButtonItem = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(recordPressed)]; // Removed the ':'
...
}
- (void) recordPressed {
NSLog(@"lets record");
[self.cameraUI startVideoCapture];
}
这篇关于UIImagePickerController startVideoCapture与自定义叠加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!