大佬教程收集整理的这篇文章主要介绍了ios – 如何在横向应用上将视频录制到屏幕上?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在从这个示例项目开始工作:https://github.com/jj0b/AROverlayExample
这非常有效.唯一的问题是它是一个肖像应用程序.因此,当我将设备旋转到横向时,视频仍会按需显示,但我的所有标签和UI现在都是横向显示的.
为了解决这个问题,我只在info.plist中设置了格局
问题是这样的:
这是我的代码:
- (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; assert( self.autoresizesSubviews ); CGPoint layerRectCenter = CGPointMake( CGRectGetMidX( frame ),CGRectGetMidY( frame ) ); // Initialization code self.captureSession = [[[AVCaptureSession alloc] init] autorelease]; // addVideoInput { AVCaptureDevice* videoDevice = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeVideo]; if (videoDevicE) { NSError *error; AVCaptureDeviceInput* videoIn = [AVCaptureDeviceInput deviceInputWithDevice: videoDevice error:&error]; if ( ! error ) { if ( [self.captureSession canAddInput:videoIn] ) [self.captureSession addInput:videoIn]; else NSLog(@"Couldn't add video input"); } else NSLog(@"Couldn't create video input"); } else NSLog(@"Couldn't create video capture device"); } // addVideoPreviewLayer { self.previewLayer = [[[AVCaptureVideoPreviewLayer alloc] initWithSession: self.captureSession] autorelease]; self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; self.previewLayer.frame = CGRectMake(0,480,300); self.previewLayer.orientation = AVCaptureVideoOrientationLandscapeRight; //self.previewLayer.frame = frame; [self.layer addSublayer: self.previewLayer]; } // run! [self.captureSession startRunning]; } return self; }
最好的一点是在根视图控制器中:
// need to add the capture view to the window here: can't do it in viewDidLoad as the window is not ready at that point - (void) viewDidAppear: (BOOL) animated { self.frontCamView = [[[FrontCamView alloc] initWithFrame: [UIScreen mainScreen].bounds] autorelease]; self.view.opaque = NO; self.view.BACkgroundColor = [UIColor clearColor]; [self.view.window addSubview: self.frontCamView]; [self.view.window sendSubviewToBACk: self.frontCamView]; }
然后执行摄像头视图本身:
@interface FrontCamView ( ) @property (retain) AVCaptureVideoPreviewLayer* previewLayer; @property (retain) AVCaptureSession* captureSession; @end // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @implementation FrontCamView @synthesize captureSession; @synthesize previewLayer; // - - - - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.captureSession = [[[AVCaptureSession alloc] init] autorelease]; // addVideoInput { AVCaptureDevice* videoDevice = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeVideo]; if (videoDevicE) { NSError *error; AVCaptureDeviceInput* videoIn = [AVCaptureDeviceInput deviceInputWithDevice: videoDevice error:&error]; if ( ! error ) { if ( [self.captureSession canAddInput:videoIn] ) [self.captureSession addInput:videoIn]; else NSLog(@"Couldn't add video input"); } else NSLog(@"Couldn't create video input"); } else NSLog(@"Couldn't create video capture device"); } // addVideoPreviewLayer { CGRect screenRect = [UIScreen mainScreen].bounds; self.previewLayer = [[[AVCaptureVideoPreviewLayer alloc] initWithSession: self.captureSession] autorelease]; self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; self.previewLayer.frame = screenRect; self.previewLayer.orientation = AVCaptureVideoOrientationPorTrait; [self.layer addSublayer: self.previewLayer]; } // run! [self.captureSession startRunning]; } return self; } - (void) dealloc { [self.captureSession stopRunning]; [previewLayer release],previewLayer = nil; [captureSession release],captureSession = nil; [super dealloc]; } @end
以上是大佬教程为你收集整理的ios – 如何在横向应用上将视频录制到屏幕上?全部内容,希望文章能够帮你解决ios – 如何在横向应用上将视频录制到屏幕上?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。