Ios 是否将UIButton添加到AVCaptureVideoPreviewLayer?
我想向AVCaptureVideoPreviewLayer添加UIButton或其他类型的按钮 以下是我尝试过的:Ios 是否将UIButton添加到AVCaptureVideoPreviewLayer?,ios,uibutton,calayer,subview,avcapturesession,Ios,Uibutton,Calayer,Subview,Avcapturesession,我想向AVCaptureVideoPreviewLayer添加UIButton或其他类型的按钮 以下是我尝试过的: [self.view.layer addSublayer:_videoPreviewLayer]; UIButton * sButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, 300, 100)]; [sButton setBackgroundColor:[UIColor yellowColor]]; [sButto
[self.view.layer addSublayer:_videoPreviewLayer];
UIButton * sButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, 300, 100)];
[sButton setBackgroundColor:[UIColor yellowColor]];
[sButton setTitle:@"Stop" forState:UIControlStateNormal];
[sButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_videoPreviewLayer addSublayer:sLabel.layer];
[_captureSession startRunning];
我还尝试了与添加的UIView类似的东西,即使AVCapture没有启动。但是,我无法向该视图添加子视图 派对有点晚了,但我一直在做类似的事情,所以我想与大家分享一下:
UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(200, 200, 100, 50);
[btn setTitle:@"Hello, world!" forState:UIControlStateNormal];
[btn setBackgroundColor:[UIColor blueColor]];
[btn becomeFirstResponder];
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, btn);
[self.view addSubview:btn];
为什么不在videoPreviewLayer的containerView.layer上添加按钮呢?那可能会起作用。我该怎么做?videoPreviewLayer.containerview.layer不存在。