我正在使用 Apple 的 AVCam 示例应用程序。
此示例使用 AVFoundation 以便在 View 上显示视频。
我正在尝试从 AVCam 制作一个风景应用程序,但运气不佳。
当屏幕方向改变时,视频在 View 上旋转显示。有没有办法处理这个问题?
最佳答案
当您创建预览层时:
captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;
以及管理轮换的方法:
-(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);
}
这对我有用。
关于iPhone App - 在横向模式下显示 AVFoundation 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6284650/