2014-04-03 97 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];