2012-10-01 63 views
0

我使用的是Apple提供的示例AVCam,但爲了我的應用程序的目的,它有所修改。然而,除了解決其他一些問題之外,沒有任何原始內容真的被觸及。但是,當它在橫向模式下工作時,我遇到了一個主要障礙。AVCam不適用於橫向模式

我有,我從另一個問題了計算器上正確的類下面的代碼:

-(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

我可以爲您提供一個變通方法,解決了這個問題對我來說,即使我敢肯定,必須有更好的解決辦法:

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

}

+0

到錄音過程中禁用自動旋轉: - (BOOL)shouldAutorotate {([[[自拍捕捉管理器]記錄器]是記錄]){ 返回YES; }否則返回NO; } – Laz