iPhone应用程序-在横向模式下显示AVFoundation视频
我正在使用苹果公司的AVCam示例应用程序 本例使用AVFoundation在视图上显示视频 我正试图使从AVCam景观应用程序没有运气iPhone应用程序-在横向模式下显示AVFoundation视频,iphone,video,rotation,avfoundation,avcam,Iphone,Video,Rotation,Avfoundation,Avcam,我正在使用苹果公司的AVCam示例应用程序 本例使用AVFoundation在视图上显示视频 我正试图使从AVCam景观应用程序没有运气 当屏幕方向改变时,视频在视图上旋转显示。是否有办法处理此问题?是否使用预览层的方向和重力设置 previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session]; previewLayer.frame = CGRectMake(0, 0, 480, 300); previewLayer.v
当屏幕方向改变时,视频在视图上旋转显示。是否有办法处理此问题?是否使用预览层的方向和重力设置
previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
previewLayer.frame = CGRectMake(0, 0, 480, 300);
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
previewLayer.orientation = AVCaptureVideoOrientationLandscapeRight;
previewLayer.automaticallyAdjustsMirroring = YES;
创建预览层时:
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);
}
这对我很有效。声明
- (BOOL)shouldAutorotate;
在你的.h
然后做:
- (BOOL)shouldAutorotate {
return NO;
}
在你的房间里
这将强制它不旋转。注意:由于方向属性已被弃用,因此您将希望旋转。