ios – 如何在横向应用上将视频录制到屏幕上?

ios – 如何在横向应用上将视频录制到屏幕上?,第1张

概述这是我的头脑. 我正在从这个示例项目开始工作:https://github.com/jj0b/AROverlayExample 这非常有效.唯一的问题是它是一个肖像应用程序.因此,当我将设备旋转到横向时,视频仍会按需显示,但我的所有标签和UI现在都是横向显示的. 为了解决这个问题,我只在info.plist中设置了格局 问题是这样的: 这是我的代码: - (id)initWithFrame:(CG 这是我的头脑.

我正在从这个示例项目开始工作: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;}

我无法弄清楚为什么视频会侧向显示,尽管专门将图层框架设置为横向CGRectMake(0,300),但它反过来会出现.

解决方法 一个非常简洁的解决方案是将视图直接添加到窗口.

最好的一点是在根视图控制器中:

// 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 – 如何在横向应用上将视频录制到屏幕上?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1034484.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存