我是iOS的新手,尝试用AvCam创建定制相机。我有困难获得景观方向预览-它旋转90度顺时针,并显示在半屏幕上。
我收到这条消息--
警告:- setOrientation:是不推荐的。
请使用AVCaptureConnection的-setVideoOrientation:
AVCaptureConnection已经设定了方向,所以我不知道我还能做什么。
我知道在iOS的早期版本(4,5)中,这个问题被问了很多次,但是这些技术/代码对我没有用(iOS 6)。
原始代码(没有对Apple做任何更改)
if ([self captureManager] == nil) {
AVCamCaptureManager *manager = [[AVCamCaptureManager alloc] init];
[self setCaptureManager:manager];
[manager release];
[[self captureManager] setDelegate:self];
if ([[self captureManager] setupSession]) {
// Create video preview layer and add it to the UI
AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:[[self captureManager] session]];
UIView *view = [self videoPreviewView];
CALayer *viewLayer = [view layer];
[viewLayer setMasksToBounds:YES];
CGRect bounds = [view bounds];
[newCaptureVideoPreviewLayer setFrame:bounds];
if ([newCaptureVideoPreviewLayer isOrientationSupported]) {
[newCaptureVideoPreviewLayer setOrientation:AVCaptureVideoOrientationPortrait];
}
[newCaptureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[viewLayer insertSublayer:newCaptureVideoPreviewLayer below:[[viewLayer sublayers] objectAtIndex:0]];
[self setCaptureVideoPreviewLayer:newCaptureVideoPreviewLayer];AVCaptureConnection块:
-(void)startRecordingWithOrientation:(AVCaptureVideoOrientation)videoOrientation; {
AVCaptureConnection *videoConnection = [AVCamUtilities connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self movieFileOutput] connections]];
if ([videoConnection isVideoOrientationSupported])
[videoConnection setVideoOrientation:videoOrientation];
[[self movieFileOutput] startRecordingToOutputFileURL:[self outputFileURL] recordingDelegate:self];}
发布于 2013-08-05 10:44:29
上次我也偶然发现了这个问题。我做了两件事解决了这个问题
- (void)deviceOrientationDidChange中手动触发AVCaptureManager.m,强制在初始化过程中更新视频方向以捕获景观模式下的视频输出。
我把它加到:发布于 2012-10-19 18:46:04
因此,这里有一个解决办法,但我相信肯定会有比这更好的解决办法。我从这个问题中得到了一部分代码:
iPhone App - Show AVFoundation video on landscape mode
但是,为了使其在iOS6上工作(它仍然显示警告),必须为每个方向调整框架:
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation持续时间:(NSTimeInterval)持续时间{
[CATransaction begin];
if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft){
captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;
captureVideoPreviewLayer.frame = CGRectMake(0, 0, 480, 320);
} else if (toInterfaceOrientation==UIInterfaceOrientationPortrait){
captureVideoPreviewLayer.orientation = UIInterfaceOrientationPortrait;
captureVideoPreviewLayer.frame = CGRectMake(0, 0, 320, 480);
} else if (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight){
captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeRight;
captureVideoPreviewLayer.frame = CGRectMake(0, 0, 480, 320);
}
[CATransaction commit];
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];}
https://stackoverflow.com/questions/12966175
复制相似问题