我想在AVCaptureVideoPreviewLayer中添加UIButton或其他类型的按钮。
以下是我的尝试:
[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没有启动也是如此。但是,我无法在该视图中添加子视图。
答案 0 :(得分:0)
参加派对的时间已经很晚了,但我一直在做类似的事情,所以我想我会分享:
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];