大佬教程收集整理的这篇文章主要介绍了iphone – 强制相机视图在风景与方向锁定,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用此代码加载视图内的摄像机视图:
AVCaptureSession *session = [[AVCaptureSession alloc] init]; AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session]; captureVideoPreviewLayer.frame = self.sessionView.bounds; [self.sessionView.layer addSublayer:captureVideoPreviewLayer]; CGRect bounds=sessionView.layer.bounds; captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; captureVideoPreviewLayer.bounds=bounds; captureVideoPreviewLayer.orientation = [[UIDevice currentDevice] orientation]; captureVideoPreviewLayer.position=CGPointMake(CGRectGetMidX(bounds),CGRectGetMidY(bounds)); AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; // device.position ; NSError *error = nil; AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; if ([device hasTorch]) { ([device supportsAVCaptureSessionPreset:AVCaptureSessionPreset1280x720]); } else { ([device supportsAVCaptureSessionPreset:AVCaptureSessionPreset640x480]); } [session addInput:input]; [session startRunning];
为了使应用程序的方向保持正确,我只选择了Xcode应用程序摘要中的那个框,其中包含:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return ((interfaceOrientation == UIInterfaceOrientationLandscapeRight)); }
当设备开启方向锁定(双击主页按钮,向右滑动,点击方向图标)时,摄像机视图将显示为纵向,其余部分处于横向状态.有没有什么办法解决这一问题?根据我的阅读,当用户打开游戏时,无法关闭方向锁定.
captureVideoPreviewLayer.orientation
使用videoOrientation属性,即
captureVideoPreviewLayer.connection.videoOrientation
>更新shouldAutorotate中的视频方向,如下所示:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if(interfaceOrientation == UIInterfaceOrientationLandscapeRight) { captureVideoPreviewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight } // and so on for other orientations return ((interfaceOrientation == UIInterfaceOrientationLandscapeRight)); }
以上是大佬教程为你收集整理的iphone – 强制相机视图在风景与方向锁定全部内容,希望文章能够帮你解决iphone – 强制相机视图在风景与方向锁定所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。