【问题标题】:Record video in Landscape always even device rotating (Landscape->Portrait->Landscape)即使设备旋转也总是以横向录制视频(横向->纵向->横向)
【发布时间】:2014-03-14 09:39:53
【问题描述】:

即使我的设备旋转(纵向->横向->纵向),我也需要始终以横向模式录制视频。

取角度很简单,我用的是hyroscope。我的问题是始终以横向录制视频。需要任何建议。

我正在使用AVCaptureSession 进行视频录制。 AVM 可变组合?不知道用什么... 请帮帮我

【问题讨论】:

    标签: ios iphone objective-c avcapturesession


    【解决方案1】:

    为什么不强制你的控制器只处于横向模式?

    你可以这样做:

    - (BOOL)shouldAutorotate 
    {
        return YES;
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return UIInterfaceOrientationLandscapeRight;
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    }
    

    【讨论】:

    • 但是当我观看来自camara roll的视频时,它会旋转。必须与水平平行
    • spec:当我们使用原生 ios 相机记录时。当我们录制视频并在屏幕上旋转设备时,视频不会旋转到,但是当我们观看他时,视频会在播放器上旋转。我想做一些像我们正在录制视频的东西(视频记录并且在设备旋转时不旋转,并且在播放器视频不旋转到,它与水平平行)
    • 好的,知道了。当用户开始录制视频时,您必须锁定旋转。我认为您应该在不录制时允许旋转。
    【解决方案2】:

    你可以试试这个代码

    @implementation PortraitViewController
    - (void)awakeFromNib
    {
        isShowingLandscapeView = NO;
        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
        [[NSNotificationCenter defaultCenter] addObserver:self
                                     selector:@selector(orientationChanged:)
                                     name:UIDeviceOrientationDidChangeNotification
                                     object:nil];
    }
    
    - (void)orientationChanged:(NSNotification *)notification
    {
        UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
        if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
            !isShowingLandscapeView)
        {
            [self performSegueWithIdentifier:@"DisplayAlternateView" sender:self];
            isShowingLandscapeView = YES;
        }
        else if (UIDeviceOrientationIsPortrait(deviceOrientation) &&
                 isShowingLandscapeView)
        {
            [self dismissViewControllerAnimated:YES completion:nil];
            isShowingLandscapeView = NO;
        }
    }
    

    还可以查看 Apple 的文档 HERE 了解详细的轮换实现。

    【讨论】:

      【解决方案3】:

      在开始录制视频之前试试这个:

      let videoDataOuputConnection = videoFileOutput.connection(with: .video)
      videoDataOuputConnection!.videoOrientation = AVCaptureVideoOrientation.landscapeLeft
      

      【讨论】:

        猜你喜欢
        • 2021-12-27
        • 2023-03-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-04
        • 2012-09-11
        相关资源
        最近更新 更多