【发布时间】:2014-03-14 09:39:53
【问题描述】:
即使我的设备旋转(纵向->横向->纵向),我也需要始终以横向模式录制视频。
取角度很简单,我用的是hyroscope。我的问题是始终以横向录制视频。需要任何建议。
我正在使用AVCaptureSession 进行视频录制。 AVM 可变组合?不知道用什么...
请帮帮我
【问题讨论】:
标签: ios iphone objective-c avcapturesession
即使我的设备旋转(纵向->横向->纵向),我也需要始终以横向模式录制视频。
取角度很简单,我用的是hyroscope。我的问题是始终以横向录制视频。需要任何建议。
我正在使用AVCaptureSession 进行视频录制。 AVM 可变组合?不知道用什么...
请帮帮我
【问题讨论】:
标签: ios iphone objective-c avcapturesession
为什么不强制你的控制器只处于横向模式?
你可以这样做:
- (BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
【讨论】:
你可以试试这个代码
@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 了解详细的轮换实现。
【讨论】:
在开始录制视频之前试试这个:
let videoDataOuputConnection = videoFileOutput.connection(with: .video)
videoDataOuputConnection!.videoOrientation = AVCaptureVideoOrientation.landscapeLeft
【讨论】: