2014-04-03 63 views
2

我想添加一个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没有启动。然而,我无法为该视图添加子视图。

+0

你为什么不加上videoPreviewLayer的containerView.layer按钮? – Chris

+0

这可以工作。我怎么做? videoPreviewLayer.containerview.layer不存在。 – DCIndieDev

回答

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];