0

我正在使用 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:

不知道如何解决这个弃用错误,或者弃用是否是导致它不转变为景观的原因。请帮忙!

4

1 回答 1

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];
}

}

于 2012-10-31T19:24:37.120 回答