我正在使用Apple提供的示例AVCam,但它已针对我的应用程序进行了一些修改。然而,除了解决其他一些问题之外,没有任何原始内容真的被触及。然而,当它以横向模式工作时,我遇到了一个主要的障碍。
我在stackoverflow上从另一个问题中获取的正确类中有以下代码:
-(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:
不确定如何解决此弃用错误,或者弃用是否导致它不会转变为格局。求救!
答案 0 :(得分:0)
我可以为您提供解决方法来解决这个问题,即使我确信必须有更好的解决方案:
-(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];
}
}