videoViewController中的摄像机视图适用于iPhone但不适用于iPad

时间:2016-01-27 01:29:40

标签: ios objective-c iphone ipad viewcontroller

我在通用iOS应用中有一个错误,它不会在iPad框架中显示相机视图。视图向左偏移。该视图完全适用于iPhone,但不适用于iPad。原始代码是2年前编写的,我想知道iOS中是否有一个更改,现在这部分代码中没有。

这是我目前所拥有的;

     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;

1 个答案:

答案 0 :(得分:0)

根据问题,如果您的项目支持自动布局,我建议只在{ CGRect bounds=self.view.layer.bounds; self.preview.videoGravity = AVLayerVideoGravityResizeAspectFill; self.preview.bounds=bounds; self.preview.position=CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds)); } 添加此行。

<强>代码: -

FILETABLE