Добавить UIButton в AVCaptureVideoPreviewLayer?

Я хочу добавить UIButton или кнопку другого типа в AVCaptureVideoPreviewLayer.

Вот что я пробовал:

[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 не был запущен. Однако я не мог добавить подвид к этому представлению.


person DCIndieDev    schedule 03.04.2014    source источник
comment
Почему бы вам не добавить кнопку на containerView.layer видеоPreviewLayer?   -  person Chris    schedule 04.04.2014
comment
Это может сработать. Как я могу это сделать? videoPreviewLayer.containerview.layer не существует.   -  person DCIndieDev    schedule 04.04.2014


Ответы (1)


Немного опоздал на вечеринку, но я работал над чем-то похожим, поэтому решил поделиться:

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];
person jekie    schedule 12.01.2017