在横向录制视频,即使设备旋转也是如此(横向 - >纵向 - >横向)

时间:2014-03-14 09:39:53

标签: ios iphone objective-c avcapturesession

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

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

我正在使用AVCaptureSession进行视频录制。 AVMutablecomposition?我不知道该用什么...... 请帮帮我

3 个答案:

答案 0 :(得分:1)

为什么不强制您的Controller仅处于横向模式?

你可以这样做:

- (BOOL)shouldAutorotate 
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeRight;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

答案 1 :(得分:1)

您可以尝试此代码

@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以了解详细轮播实现。

答案 2 :(得分:0)

在开始录制视频之前尝试此操作:

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