Iphone AvCam iOS 6中的景观
我是iOS新手,尝试使用AvCam创建自定义相机。我在获取横向预览时遇到问题——它将视图顺时针旋转90度,并在半屏幕上显示 我收到这个消息-- 警告:-[setOrientation:]已弃用 请使用AVCaptureConnection的-setVideoOrientation: AVCaptureConnection已经设置了方向,所以我不知道我还应该做什么 我知道这个问题在以前版本的iOS(4,5)中被问了很多次,但这些技术/代码中没有一种对我有效(iOS 6) 原始代码(未对Apple进行任何更改) AVCaptureConnection区块:Iphone AvCam iOS 6中的景观,iphone,xcode,ios6,landscape,avcam,Iphone,Xcode,Ios6,Landscape,Avcam,我是iOS新手,尝试使用AvCam创建自定义相机。我在获取横向预览时遇到问题——它将视图顺时针旋转90度,并在半屏幕上显示 我收到这个消息-- 警告:-[setOrientation:]已弃用 请使用AVCaptureConnection的-setVideoOrientation: AVCaptureConnection已经设置了方向,所以我不知道我还应该做什么 我知道这个问题在以前版本的iOS(4,5)中被问了很多次,但这些技术/代码中没有一种对我有效(iOS 6) 原始代码(未对Apple进
-(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];
}所以,这里有一个解决办法,但我相信一定有比这个更好的解决方案。我从这个问题中得到了部分代码: 但为了在iOS6上工作,必须为每个方向调整框架(并且仍然显示警告):
-(无效)WillAnimateRotationInterfaceOrientation: (UIInterfaceOrientation)到接口方向 持续时间:(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];
}上次我也偶然发现了这个问题。我通过做两件事解决了这个问题
替换
if ([newCaptureVideoPreviewLayer isOrientationSupported]) {
[newCaptureVideoPreviewLayer setOrientation:AVCaptureVideoOrientationPortrait];
}
与
if ([newCaptureVideoPreviewLayer.connection isVideoOrientationSupported]) {
[newCaptureVideoPreviewLayer.connection setVideoOrientation:[UIDevice currentDevice].orientation];
}
-(无效)设备定向IDChange
在AVCaptureManager.m
我将其添加到:
- (BOOL) setupSession
{
BOOL success = NO;
...
AVCamRecorder *newRecorder = [[AVCamRecorder alloc] initWithSession:[self session] outputFileURL:self.lastOutputfileURL];
[newRecorder setDelegate:self];
[self performSelector:@selector(deviceOrientationDidChange)];
...
return success;
}
此线程有一个解决方向警告的解决方案--
- (BOOL) setupSession
{
BOOL success = NO;
...
AVCamRecorder *newRecorder = [[AVCamRecorder alloc] initWithSession:[self session] outputFileURL:self.lastOutputfileURL];
[newRecorder setDelegate:self];
[self performSelector:@selector(deviceOrientationDidChange)];
...
return success;
}