gpt4 book ai didi

iphone - 使用 AV Foundation 时旋转 AV 视频预览区域和其他元素

转载 作者:可可西里 更新时间:2023-11-01 05:04:54 26 4
gpt4 key购买 nike

我开始了一个项目,使用 UIImagePickerController 来捕获静态图像。由于叠加层和刚刚捕获的图像之间的交互不佳,我已经放弃使用这种简单的机制。问题如下:如果您有一个叠加层处于事件状态并拍摄照片,则刚拍摄的图像会旋转以在纵向方向上进行纵横比填充,当用户看到使用或重新拍摄图像的选项时。发生这种情况时,无法关闭叠加层或旋转叠加层以对应新的静止图像预览方向。不好。

我决定尝试使用 AV Foundation 的各种机制重新实现 UIImagePickerController 的静止图像捕获行为。这非常容易设置,但我仍然有一些挥之不去的问题:

1) 我想重新定位机制以类似于 UI 在标准 UIImagePickerController 中的工作方式。如您所知,在此 Controller 中,无论手机如何旋转,按钮栏始终固定在纵向的底部。在这个按钮栏中,按钮中的字形本身会旋转,但其他所有内容都保持不变。用于闪光灯设置、相机切换和选项的叠加控件会重新定向。我怎样才能让这个标签栏在旋转这些其他元素时保持固定?有没有办法从轮换中排除某些元素?

2) 进行自动重定向后,我希望 AVVideoCaptureLayer 始终保持事件状态并占据整个屏幕。当设备执行重新定向旋转时,该层的尺寸变得奇怪(缩小)并且视频源本身关闭 90 度。很明显,该层正在旋转但没有旋转到全屏尺寸,并且视频源本身的行为不符合预期。我希望视频在整个旋转过程中保持固定并占据整个屏幕,始终向上,并且在旋转过程中不调整预览大小。但我也希望能够像第 1 项中那样进行某些元素的重新定向。

非常感谢任何说明如何实现此目的的示例代码。

最佳答案

刚刚发现在 AVCaptureVideoPreviewLayer 上使用 orientation 属性已被弃用。这是一个更新的解决方案(尽管@Jaret Ward 共享的以前的解决方案工作少得多:):

使用推荐的方法,通过 AVCaptureConnection 中的 setVideoOrientation 更改它。我会在 viewDidAppear 和您的轮换回调之一中添加对此的调用。

//setup a connection to the preview layer
AVCaptureConnection *connection;
connection = [self.videoPreviewLayer connection];
[connection setVideoOrientation:[self avOrientationForDeviceOrientation:[[UIDevice currentDevice] orientation]]];

//translate the orientation
- (AVCaptureVideoOrientation)avOrientationForDeviceOrientation:(UIDeviceOrientation)deviceOrientation {

AVCaptureVideoOrientation result = deviceOrientation;
if ( deviceOrientation == UIDeviceOrientationLandscapeLeft )
result = AVCaptureVideoOrientationLandscapeRight;
else if ( deviceOrientation == UIDeviceOrientationLandscapeRight )
result = AVCaptureVideoOrientationLandscapeLeft;
else if( deviceOrientation == UIDeviceOrientationPortrait)
result = AVCaptureVideoOrientationPortrait;
else if( deviceOrientation == UIDeviceOrientationPortraitUpsideDown)
result = AVCaptureVideoOrientationPortraitUpsideDown;
return result;
}

关于iphone - 使用 AV Foundation 时旋转 AV 视频预览区域和其他元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6802264/

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