Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone AVFoundation相机预览方向错误_Iphone_Objective C_Xcode_Ipad_Avfoundation - Fatal编程技术网

Iphone AVFoundation相机预览方向错误

Iphone AVFoundation相机预览方向错误,iphone,objective-c,xcode,ipad,avfoundation,Iphone,Objective C,Xcode,Ipad,Avfoundation,我正在制作一个定制相机,在iPad内部有一个小的预览区域,但是,预览中的流是顺时针旋转的 我已经看过了苹果上的AVCam演示和SquareCam演示,但都没有看到解决方案。StackOverflow上的所有AVFoundation定向线程都专门讨论输出定向,而不是输入定向 以下是我正在使用的会话代码: AVCaptureDevice *frontalCamera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

我正在制作一个定制相机,在iPad内部有一个小的预览区域,但是,预览中的流是顺时针旋转的

我已经看过了苹果上的AVCam演示和SquareCam演示,但都没有看到解决方案。StackOverflow上的所有AVFoundation定向线程都专门讨论输出定向,而不是输入定向

以下是我正在使用的会话代码:

AVCaptureDevice *frontalCamera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    _session = [[AVCaptureSession alloc] init];
    [_session beginConfiguration];
    NSError *error;
    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:frontalCamera error:&error];
    [_session addInput:input];
    _output = [[AVCaptureStillImageOutput alloc] init];
    [_output setOutputSettings:[[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG,AVVideoCodecKey,nil]];
    [_session addOutput:_output];
    AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:_session];
    previewLayer.frame = self.imageViewCamera.bounds;
    previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
    [self.imageViewCamera.layer addSublayer:previewLayer];
    _session.sessionPreset = AVCaptureSessionPreset640x480;
    [_session commitConfiguration];
    [_session startRunning];

任何帮助都将不胜感激

这已被弃用,但您可以逆时针更改预览层的方向

previewLayer.orientation = AVCaptureVideoOrientationLandscapeRight;

不过,我不确定不推荐的解决方案是什么。

苹果的iOS 6文档说使用
videoOrientation(AVCaptureConnection)

层的方向。(在iOS 6.0中已弃用。请使用 (AVCaptureConnection)而不是。)

因此,请使用:

[[AVCaptureVideoPreviewLayer connection] setVideoOrientation: AVCaptureVideoOrientationLandscapeRight];


这是可行的,但我想要一个非去润滑的解决方案。现在就可以了,谢谢!
AVCaptureVideoPreviewLayer.connection.videoOrientation= AVCaptureVideoOrientationLandscapeRight;