【发布时间】:2011-06-08 20:11:57
【问题描述】:
我正在使用 Apple 的 AVCam 示例应用程序。
此示例使用 AVFoundation 在视图上显示视频。
我正在尝试通过 AVCam 制作一个风景应用程序,但没有成功。
当屏幕方向改变时,视频会在视图上旋转显示。有没有办法处理这个问题?
【问题讨论】:
标签: iphone video rotation avfoundation avcam
我正在使用 Apple 的 AVCam 示例应用程序。
此示例使用 AVFoundation 在视图上显示视频。
我正在尝试通过 AVCam 制作一个风景应用程序,但没有成功。
当屏幕方向改变时,视频会在视图上旋转显示。有没有办法处理这个问题?
【问题讨论】:
标签: iphone video rotation avfoundation avcam
当您创建预览层时:
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);
}
这对我有用。
【讨论】:
您是否使用预览图层的方向和重力设置?
previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
previewLayer.frame = CGRectMake(0, 0, 480, 300);
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
previewLayer.orientation = AVCaptureVideoOrientationLandscapeRight;
previewLayer.automaticallyAdjustsMirroring = YES;
【讨论】:
声明
- (BOOL)shouldAutorotate;
在你的 .h 中。
然后做:
- (BOOL)shouldAutorotate {
return NO;
}
在您的 .m 中
这将强制它不旋转。
【讨论】: