gpt4 book ai didi

ios - iPhone : Container View Controller and Camera Preview: preview is not displayed in child view controller

转载 作者:行者123 更新时间:2023-11-29 11:01:07 24 4
gpt4 key购买 nike

我已经找到并阅读了这个 tutorial .确实很好!我故意使用“阅读”这个词。早知道就不来这里问了。

现在:我试图将我读过的内容插入到我的应用程序中。我需要带有静态图像和相机预览控件的不同叠加层。我需要相机预览在应用程序的其余部分旋转时保持静止。我需要它是 AVFoundation,因为会有很多额外的图像和相机功能。我想旋转所有应用程序,但相机预览。一个自制的容器 View Controller 将成为铰链点。在它之外,应用程序旋转。它控制它的 child 的旋转,我希望能够减少我的手动旋转到所述容器 View Controller 的相机预览 subview Controller 的覆盖。

(此外:除此之外,我还使用链接的 Storyboard、ARC 和 CoreData(稍后用于照片))

要点是:我在容器 View Controller 容器 View 中有这个 View Controller 。那就是我想要预览的那个。我想要另一个容器 View Controller subview Controller 中的静止图像,第三个 subview Controller 是照片的浏览器。稍后会有按钮和手势从一个 child 导航到另一个。捕获 session 管理器是容器 View Controller 的一个属性,即父级。

我已经设置了所有@properties(在捕获 session 管理器、容器 View Controller 和相机预览 View Controller 中),当它们不存在时将被创建。我已经为相机预览 View Controller 提供了一个捕获 session 管理器的属性,但应该只是指向父 session 管理器的指针(懒惰或 fatal error ?)。

据我所知,通过调试器单步执行,连接已经建立。现在,在相机预览 View Controller 的 viewDidLoad 方法中,我尝试显示预览层。

然后我看到... ...只有一个空白的白色 View :(

我可能忘记了什么?

此时应该已经建立了父子连接。 embed segue 设置子项的捕获管理器:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"EmbedCameraPreview"])
{ // present destination view
if ([[segue destinationViewController] isKindOfClass:[CameraPreviewViewController class]]) {
CameraPreviewViewController * destinationVC = (CameraPreviewViewController *)[segue destinationViewController];
[destinationVC setCaptureManager:[self captureManager]];
}
[self addChildView:[segue destinationViewController]];
}
}

- (void) addChildView: (UIViewController*) content {
[self addChildViewController:content];
content.view.frame = [self maxFrame];
[content didMoveToParentViewController:self];
}

- (CGRect) maxFrame {
return [[[self view] layer] bounds];
}

child 的捕获管理器是私有(private)的(在 .m 文件中),具有公共(public) setter :

接口(interface):

@property (retain, nonatomic) CaptureSessionManager *captureManager;

实现:

@synthesize captureManager;

- (void)setCaptureManager:(CaptureSessionManager *) newCaptureManager {
if (captureManager != newCaptureManager) {
captureManager = newCaptureManager;
}
}

- (CaptureSessionManager *) captureManager {
if (captureManager != nil) {
return captureManager;
}

if ([[self parentViewController] isKindOfClass:[CameraContainerViewController class]]) {
CameraContainerViewController* parentView = (CameraContainerViewController*)[self parentViewController];
[self setCaptureManager:[parentView captureManager]];
}

return captureManager;
}
子级的

viewDidLoad 从父级的 addChildView 中的 content.view.frame = [self maxFrame] 调用(见上文: prepareForSegue):

- (void) displayCameraPreview
{
CGRect layerRect = [[[self view] layer] bounds];
[[[self captureManager] previewLayer] setBounds:layerRect];
[[[self captureManager] previewLayer] setPosition:CGPointMake(CGRectGetMidX(layerRect),
CGRectGetMidY(layerRect))];
[[[self view] layer] addSublayer:[[self captureManager] previewLayer]];
}

- (void) initDisplay {
[self displayCameraPreview];
}

- (void)viewDidLoad {
[super viewDidLoad];

// Do any additional setup after loading the view.
[self initDisplay];
}

请帮忙? :(

最佳答案

非常抱歉!

再次感谢上述教程的作者。干得好!

在拆分代码以设置不同的 View Controller 时,我忽略了一个小细节。应该开始 session ,不是吗?这是可以使用的来源:

- (void) displayCameraPreview
{
CGRect layerRect = [[[self view] layer] bounds];
[[[self captureManager] previewLayer] setBounds:layerRect];
[[[self captureManager] previewLayer] setPosition:CGPointMake(CGRectGetMidX(layerRect),
CGRectGetMidY(layerRect))];
[[[self view] layer] addSublayer:[[self captureManager] previewLayer]];

[[captureManager captureSession] startRunning];
}

关于ios - iPhone : Container View Controller and Camera Preview: preview is not displayed in child view controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15898261/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com