isOrientationSupported在IOS中已弃用

时间:2012-07-17 23:36:16

标签: iphone objective-c ios

我收到此错误,我不知道如何修复它。

WARNING: -[<AVCaptureVideoPreviewLayer: 0xad482c0> isOrientationSupported] is deprecated.  Please use AVCaptureConnection's -isVideoOrientationSupported
然而,当我看到苹果documentation时,它说它是Mac OS功能..而不是IOS ......所以我有点困惑...期待得到一些答案..谢谢..

3 个答案:

答案 0 :(得分:26)

一些示例代码也适用于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];
    }                
}

答案 1 :(得分:3)

AVCaptureConnection也适用于iOS here。你可能看错了文档。

答案 2 :(得分:1)

上面回答的示例代码工作正常。但需要取代自我。 interfaceOrientation with AVCaptureVideoOrientation。

编辑的代码如下。

if ([captureVideoPreviewLayer.connection isVideoOrientationSupported])
{
    [captureVideoPreviewLayer.connection setVideoOrientation:AVCaptureVideoOrientationPortrait];
}

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

欢迎编辑和建议。

相关问题