当前位置: 首页 > 工具软件 > LBXScan > 使用案例 >

解决LBXScan在ipad上横屏扫码时摄像头旋转90度

徐星阑
2023-12-01

在LBXScanNative.m中

- (void)initParaWithPreView:(UIView*)videoPreView ObjectType:(NSArray*)objType cropRect:(CGRect)cropRect success:(void(^)(NSArray<LBXScanResult*> *array))block

{

...........

 _preview =[AVCaptureVideoPreviewLayer layerWithSession:_session];
    _preview.videoGravity = AVLayerVideoGravityResizeAspectFill;

...........

//_preview.orientation = UIDeviceOrientationLandscapeLeft;


//添加这个方法
 
_preview.connection.videoOrientation =  [self videoOrientationFromCurrentDeviceOrientation];    //指定屏幕方向

}


- (AVCaptureVideoOrientation) videoOrientationFromCurrentDeviceOrientation {
    switch ([[UIApplication sharedApplication]statusBarOrientation]) {
        case UIInterfaceOrientationPortrait: {
            return AVCaptureVideoOrientationPortrait;
        }
        case UIInterfaceOrientationLandscapeLeft: {
            return AVCaptureVideoOrientationLandscapeLeft;
        }
        case UIInterfaceOrientationLandscapeRight: {
            return AVCaptureVideoOrientationLandscapeRight;
        }
        case UIInterfaceOrientationPortraitUpsideDown: {
            return AVCaptureVideoOrientationPortraitUpsideDown;
        }
    }
}

 类似资料: