isOrientationSupported在IOS中已被弃用。

8

我遇到了这个错误,但是不知道如何解决它。

WARNING: -[<AVCaptureVideoPreviewLayer: 0xad482c0> isOrientationSupported] is deprecated.  Please use AVCaptureConnection's -isVideoOrientationSupported

然而,当我查看苹果公司的文档时,发现这是一个针对Mac OS的函数,而不是针对iOS的,让我有些困惑。期待得到答案。谢谢。
3个回答

26

以下是在 Android 6.0以前版本中同样有效的示例代码:

if ([captureVideoPreviewLayer respondsToSelector:@selector(connection)])
{
    if ([captureVideoPreviewLayer.connection isVideoOrientationSupported])
    {
        [captureVideoPreviewLayer.connection setVideoOrientation:self.interfaceOrientation];
    }
}
else
{
    // Deprecated in 6.0; here for backward compatibility
    if ([captureVideoPreviewLayer isOrientationSupported])
    {
        [captureVideoPreviewLayer setOrientation:self.interfaceOrientation];
    }                
}

你应该使用AVCaptureVideoOrientation而不是UIInterfaceOrientation,即self.interfaceOrientation。 - Despotovic

3

AVCaptureConnection也适用于iOS,此处有相关文档。您可能在错误的文档中查找。


1
上面的示例代码可以正常工作。但需要将self.interfaceOrientation替换为AVCaptureVideoOrientation。
编辑后的代码如下。
if ([captureVideoPreviewLayer.connection isVideoOrientationSupported])
{
    [captureVideoPreviewLayer.connection setVideoOrientation:AVCaptureVideoOrientationPortrait];
}

根据要求,方向将是纵向或横向。

欢迎编辑和建议。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接