简体   繁体   English

videoViewController中的摄像机视图可在iPhone上使用,但不能在iPad上使用

[英]Video camera view in videoViewController works on iPhone but not iPad

I have a bug in a Universal iOS app that does not display the camera view in the iPad frame. 我在Universal iOS应用中存在一个错误,该错误未在iPad框架中显示相机视图。 The view is offset to the left. 该视图向左偏移。 The view sits perfectly in an iPhone, but not on iPad. 该视图可以完美地放置在iPhone上,但不适用于iPad。 The original code was written 2 years ago and I am wondering if there has been a change in iOS that is now missing from this section of code. 原始代码是2年前编写的,我想知道iOS中是否有更改,而此部分代码中现在没有这些更改。

Here is what I have at the moment; 这是我目前所拥有的;

     self.preview = [AVCaptureVideoPreviewLayer layerWithSession:self.session];
AVCaptureConnection *avcc = [self.preview connection];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  [avcc setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
else
    [avcc setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
CGRect rect = [[[self view] layer] bounds];
[self.preview setBounds:CGRectMake(0, 0, rect.size.height, rect.size.width)];
[self.preview setPosition:CGPointMake(CGRectGetMidY(rect), CGRectGetMidX(rect))];
self.preview.videoGravity = AVLayerVideoGravityResizeAspectFill;

As per the problem , what I can suggest just add this line in viewDidLayoutSubviews() if your project support Auto Layout . 根据问题,我的建议是,如果您的项目支持Auto Layout,只需在viewDidLayoutSubviews()添加这一行。

Code:- 码:-

{
    CGRect bounds=self.view.layer.bounds;
    self.preview.videoGravity = AVLayerVideoGravityResizeAspectFill;  
    self.preview.bounds=bounds;
    self.preview.position=CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM