gpt4 book ai didi

ios - UIScrollView 显示相机

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

我已经通过创建 AVCaptureVideoPreviewLayer 创建了一个要在屏幕上显示的相机 View ,现在我希望它能够显示在我的 ScrollView 内。目前我的 ScrollView 设置为处理 UIImageViews 但不是相机层。以下是它们如何协同工作:

//设置相机 View [self setCaptureManager:[[CaptureManager alloc] init]];

[[self captureManager] addVideoInput];

[[self captureManager] addVideoPreviewLayer];
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];


int PageCount = 2;
NSMutableArray *arrImageName =[[NSMutableArray alloc]initWithObjects:settingsView,captureManager,nil];
UIScrollView *scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
scroller.scrollEnabled=YES;
scroller.backgroundColor = [UIColor clearColor];
[scroller setShowsHorizontalScrollIndicator:NO];
scroller.pagingEnabled = YES;
scroller.bounces = NO;
scroller.delegate = self;
[self.view addSubview:scroller];
int width=scroller.frame.size.width;
int xPos=0;
for (int i=0; i<PageCount; i++)
{
UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(xPos, 0, scroller.frame.size.width, scroller.frame.size.height)];
UIView *view2 = [arrImageName objectAtIndex:i];
[view1 addSubview:view2];
[scroller addSubview:view1];
scroller.contentSize = CGSizeMake(width, 0);
width +=scroller.frame.size.width;
xPos +=scroller.frame.size.width;
}

捕获管理器处理AVCaptureVideoPreviewLayer,这一切都工作正常并自行显示。我试图让它显示在我的 scrollView 中,所以我注释掉了 CGRect layerRect ,而是尝试将其显示在我在 scrollView 上的数组。在 scrollView 的底部,我有一个 UIImageView 正在获取数组并显示它,但是这显然不起作用,因为相机不是图像。我可以在底部更改或查看哪些内容才能使这项工作正常进行?将其更改为 UIView?谢谢。

最佳答案

在循环之后,只需在 UIScrollView 的底部创建并添加 UIView(具有适当的位置和矩形)。然后,将视频预览层作为子层添加到添加到 scrollView 的 View 中。祝你好运!

编辑好的,试试这个:

[[self captureManager] addVideoInput];

[[self captureManager] addVideoPreviewLayer];
CGRect layerRect = [[[self view] layer] bounds];
[[[self captureManager] previewLayer] setBounds:layerRect];
[[[self captureManager] previewLayer] setPosition:CGPointMake(CGRectGetMidX(layerRect),
CGRectGetMidY(layerRect))];
UIView *captureView = [[UIView alloc] initWithFrame:self.view.bounds];
[[captureView layer] addSublayer:[[self captureManager] previewLayer]];

[[captureManager captureSession] startRunning];


int PageCount = 2;
NSMutableArray *arrImageName =[[NSMutableArray alloc]initWithObjects:settingsView,captureView,nil];
UIScrollView *scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
scroller.scrollEnabled=YES;
scroller.backgroundColor = [UIColor clearColor];
[scroller setShowsHorizontalScrollIndicator:NO];
scroller.pagingEnabled = YES;
scroller.bounces = NO;
scroller.delegate = self;
[self.view addSubview:scroller];
int width=scroller.frame.size.width;
int xPos=0;
for (int i=0; i<PageCount; i++)
{
UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(xPos, 0, scroller.frame.size.width, scroller.frame.size.height)];
UIView *view2 = [arrImageName objectAtIndex:i];
[view1 addSubview:view2];
[scroller addSubview:view1];
scroller.contentSize = CGSizeMake(width, 0);
width +=scroller.frame.size.width;
xPos +=scroller.frame.size.width;
}

关于ios - UIScrollView 显示相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19443606/

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