Xcode AVCam不';不适用于景观模式
我使用的是苹果公司提供的AVCam示例,但出于我应用程序的目的,对其进行了一些修改。然而,除了修复一些其他问题外,没有任何原始内容被真正触及。然而,当它在横向模式下工作时,我遇到了一个主要障碍 我从stackoverflow的另一个问题中获得了正确的类中的以下代码:Xcode AVCam不';不适用于景观模式,xcode,landscape,deprecated,xcode4.5,avcam,Xcode,Landscape,Deprecated,Xcode4.5,Avcam,我使用的是苹果公司提供的AVCam示例,但出于我应用程序的目的,对其进行了一些修改。然而,除了修复一些其他问题外,没有任何原始内容被真正触及。然而,当它在横向模式下工作时,我遇到了一个主要障碍 我从stackoverflow的另一个问题中获得了正确的类中的以下代码: -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInte
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[CATransaction begin];
if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft){
captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;
} else {
captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;
}
[CATransaction commit];
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
但是,它不起作用。此代码的目的是在移动手机时允许横向移动。每次移动方向时,控制台中都会弹出一条警告:
WARNING: -[<AVCaptureVideoPreviewLayer: 0x1ed97620> setOrientation:] is deprecated. Please use AVCaptureConnection's -setVideoOrientation:
警告:-[setOrientation:]已弃用。请使用AVCaptureConnection的-setVideoOrientation:
不确定如何修复此弃用错误,或者是否是弃用导致它无法切换到横向。救命啊 我可以为您提供一个解决方案,为我解决这个问题,即使我确信一定有更好的解决方案:
-(void)willAnimateRotationToInterfaceOrientation (UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
if (![[[self captureManager] recorder] isRecording]) {
[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];
}
}要在录制过程中禁用自动旋转:-(BOOL)应自动旋转{if(![[[self captureManager]recorder]isRecording]){返回是;}否则返回否;}