gpt4 book ai didi

objective-c - AVCaptureVideoPreviewLayer方向错误

转载 作者:行者123 更新时间:2023-12-03 17:11:17 25 4
gpt4 key购买 nike

我有一个奇怪的问题。我正在我的应用程序中录制视频。一切正常,直到我将设备旋转 180 度。在哪种横向模式下启动游戏并不重要,视频会正确启动,但一旦我旋转(例如从横向左向右),视频就会开始垂直录制。我画了一张图来展示: enter image description here

我正在尝试这样设置视频方向:- (BOOL)应该自动旋转{

UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(@"Left");
captureVideoPreviewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
return YES;
}
else if(orientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"Right");
captureVideoPreviewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;
return YES;
}

return NO;

}但这似乎根本不起作用。我设置 captureVideoPreviewLayer.frame=self.view.bounds;还是不行

最佳答案

你的做法是正确的,但我不确定你的方向。我认为应该是

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

这是完整的方法,您可以通过从 shouldAutorotate 方法调用它来尝试:

- (void)autoRotateVideoOrientation {
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
switch (orientation) {
case UIInterfaceOrientationPortrait:
captureVideoPreviewLayer.connection.videoOrientation = AVCaptureVideoOrientationPortrait;
break;
case UIInterfaceOrientationPortraitUpsideDown:
captureVideoPreviewLayer.connection.videoOrientation = AVCaptureVideoOrientationPortraitUpsideDown;
break;
case UIInterfaceOrientationLandscapeLeft:
captureVideoPreviewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
break;
case UIInterfaceOrientationLandscapeRight:
captureVideoPreviewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;
break;
default:
break;
}
}

关于objective-c - AVCaptureVideoPreviewLayer方向错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25801405/

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