对于我的应用我想创建一个自定义相机覆盖并创建一个UIImagePickerController来开始录制视频。 (下同)
- (IBAction)RecordVideo:(UIButton *)sender {
//initialise camera view
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraUI.cameraDevice = UIImagePickerControllerCameraDeviceFront;
cameraUI.showsCameraControls = NO;
cameraUI.navigationBarHidden = YES;
cameraUI.toolbarHidden = YES;
OverlayView *overlay = [[OverlayView alloc]
initWithFrame:CGRectMake(0, 0, 20,20)];
cameraUI.cameraOverlayView = overlay;
[self presentViewController:cameraUI animated:YES completion:nil];
}
作为cameraOverlayView
的一部分,我实例化了一个UIButton:
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
//clear the background color of the overlay
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
... some overlay UI stuff
UIButton *captureBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIImage *captureBtnImg = [UIImage imageNamed:@"captureBtn.png"];
[captureBtn setBackgroundImage:captureBtnImg forState:UIControlStateNormal];
captureBtn.frame = CGRectMake(self.frame.size.width/2 - 15,
430,
80,
80);
[self addSubview:captureBtn];
}
return self;
}
那么如何为此按钮创建IBAction
,然后可以UIImagePickerController cameraUI
开始录制?
如果有人也可以向我解释如何通过特定按钮调用IBActions,那也是惊人的,因为这对我来说似乎是黑魔法?
答案 0 :(得分:1)
你可以添加这样的目标,
[captureBtn addTarget:self action:@selector(captureBtnclick:) forControlEvents:UIControlEventTouchUpInside];
你的行动方法应该是这样的
-(void)captureBtnclick :(UIButton*)sender{
//handle your task on click here
}
为什么要在其上添加图层?您可以通过设置类似
的媒体类型来使用来自imagePicker的默认视频录制cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
更新参与评论
您可以使用按钮点击,
[picker startVideoCapture]; //in your case cameraUI i think
更新2 :
你的.h文件中的,
@property UIImagePickerController *cameraUI;
然后在你的方法RecordVideo
中使用like,
self.cameraUI = [[UIImagePickerController alloc] init];
self.cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
//etc.....
通过这种方式,您可以camaraUI
self
希望这会有所帮助:)